Fix coding standards in Geocoder module

Created on 7 June 2022, almost 3 years ago
Updated 15 July 2024, 9 months ago

Problem/Motivation

Need to fix the coding standard issues.

Steps to reproduce

After Running phpcs getting following errors and warnings:
1. t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
2. Description for the @return value is missing.
3. The class short comment should describe what the class does and not the class name.
4. #description values usually have to run through t() for translation.
5. The array declaration extends to column 112 (the limit is 80).

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇮🇳India akshaydalvi212

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India riddhi.addweb

    I tried to apply the patch, but when applied it shows an error. Seems like the patch is not working.

    Checking patch geocoder.module...
    error: while searching for:
    
    /**
     * Implements hook_geocoder_provider_info_alter().
     *
     * @param array $plugins
     *   The list of plugin definitions to alter, passed by reference.
     */
    function geocoder_geocoder_provider_info_alter(array &$plugins): void {
      // If composer is caching plugin locations remove them.
    
    error: patch failed: geocoder.module:40
    error: geocoder.module: patch does not apply
    Checking patch modules/geocoder_address/src/AddressService.php...
    error: while searching for:
    use CommerceGuys\Addressing\Formatter\PostalLabelFormatter;
    
    /**
     * Class AddressService.
     *
     * @package Drupal\geocoder_address
     */
    
    error: patch failed: modules/geocoder_address/src/AddressService.php:12
    error: modules/geocoder_address/src/AddressService.php: patch does not apply
    Checking patch modules/geocoder_field/geocoder_field.module...
    Hunk #1 succeeded at 131 (offset -2 lines).
    error: while searching for:
              // Allow others modules to adjust the address string.
              Drupal::service('module_handler')->alter('geocode_entity_field_address_string', $value['value'], $field);
    
              $failure_status_message = t("Unable to geocode '@text'.", ['@text' => isset($value['value']) ? $value['value'] : '']);
              $geo_collection = isset($value['value']) ? \Drupal::service('geocoder')->geocode($value['value'], $providers) : NULL;
              break;
    
    
    error: patch failed: modules/geocoder_field/geocoder_field.module:247
    error: modules/geocoder_field/geocoder_field.module: patch does not apply
    Checking patch modules/geocoder_field/src/Geocoder/Provider/File.php...
    error: while searching for:
          }
        }
    
        list($degrees, $minutes, $seconds) = $coordinate;
        $sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1;
        $value = $sign * ($degrees + $minutes / 60 + $seconds / 3600);
    
    
    error: patch failed: modules/geocoder_field/src/Geocoder/Provider/File.php:75
    error: modules/geocoder_field/src/Geocoder/Provider/File.php: patch does not apply
    Checking patch modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php...
    error: while searching for:
        $element['providers'] = $this->providerPluginManager->providersPluginsTableList($enabled_providers);
    
        // Set a validation for the providers selection.
        $element['providers']['#element_validate'] = [[get_class($this), 'validateProvidersSettingsForm']];
    
        $element['dumper'] = [
          '#type' => 'select',
    
    error: patch failed: modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php:203
    error: modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php: patch does not apply
    Checking patch modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php...
    error: while searching for:
       */
      public function getSettingsForm(FieldConfigInterface $field, array $form, FormStateInterface &$form_state) {
    
        $geocoder_settings_link = $this->link->generate(t('Edit options in the Geocoder configuration page</span>'), Url::fromRoute('geocoder.settings', [], [
          'query' => [
            'destination' => Url::fromRoute('<current>')
              ->toString(),
    
    error: patch failed: modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php:165
    error: modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php: patch does not apply
    Checking patch modules/geocoder_field/src/PreprocessorPluginManager.php...
    error: while searching for:
          $geocoder_fields[$field_name] = [
            'field_name' => $field_name,
            'field_value' => $field,
            'weight' => isset($geocoder['weight']) ? $geocoder['weight'] : 0,
          ];
        }
    
    
    error: patch failed: modules/geocoder_field/src/PreprocessorPluginManager.php:85
    error: modules/geocoder_field/src/PreprocessorPluginManager.php: patch does not apply
    Checking patch modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php...
    error: while searching for:
        $summary['intro'] = $this->pluginDefinition['description'];
        $summary += parent::settingsSummary();
        unset($summary['dumper']);
        $summary['adapter'] = t('Output format: @format', [
          '@format' => !empty($adapter) ? $adapters[$adapter] : $this->t('Not set'),
        ]);
        return $summary;
    
    error: patch failed: modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php:170
    error: modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php: patch does not apply
    Checking patch src/ConfigurableProviderUsingHandlerWithAdapterBase.php...
    error: while searching for:
       * {@inheritdoc}
       */
      protected function doGeocode($source) {
        $this->throttle->waitForAvailability($this->pluginId, isset($this->configuration['throttle']) ? $this->configuration['throttle'] : []);
        return parent::doGeocode($source);
      }
    
    
    error: patch failed: src/ConfigurableProviderUsingHandlerWithAdapterBase.php:94
    error: src/ConfigurableProviderUsingHandlerWithAdapterBase.php: patch does not apply
    Checking patch src/Controller/GeocoderApiEnpoints.php...
    error: while searching for:
    use Drupal\Core\Cache\CacheableMetadata;
    
    /**
     * Class GeocoderApiEnpoints.
     */
    class GeocoderApiEnpoints extends ControllerBase {
    
    
    error: patch failed: src/Controller/GeocoderApiEnpoints.php:18
    error: src/Controller/GeocoderApiEnpoints.php: patch does not apply
    Checking patch src/DumperPluginManager.php...
    error: while searching for:
        if (\in_array($field_config->getType(), $this->maxLengthFieldTypes, TRUE) &&
          \strlen($dumper_result) > $field_config->getFieldStorageDefinition()->getSetting('max_length')) {
    
          $incompatibility_warning_message = t("The '@field_name' field 'max length' property is not compatible with the chosen '@dumper' dumper.<br>Thus <b>be aware</b> <u>the dumper output result has been truncated to @max_length chars (max length)</u>.<br> You are advised to change the '@field_name' field definition or chose another compatible dumper.", [
            '@field_name' => $field_config->getLabel(),
            '@dumper' => $dumper->getPluginId(),
            '@max_length' => $field_config->getFieldStorageDefinition()->getSetting('max_length'),
    
    error: patch failed: src/DumperPluginManager.php:153
    error: src/DumperPluginManager.php: patch does not apply
    Checking patch src/GeocoderThrottleInterface.php...
    error: while searching for:
       *   or null not to limit the requests.
       *
       * @return void|null
       */
      public function waitForAvailability(string $key, array $throttle_info);
    
    
    error: patch failed: src/GeocoderThrottleInterface.php:19
    error: src/GeocoderThrottleInterface.php: patch does not apply
    Checking patch src/Plugin/Geocoder/Provider/Random.php...
    error: while searching for:
    use Geocoder\Model\AdminLevelCollection;
    
    /**
     * Class Random.
     *
     * @GeocoderProvider(
     *  id = "random",
    
    error: patch failed: src/Plugin/Geocoder/Provider/Random.php:9
    error: src/Plugin/Geocoder/Provider/Random.php: patch does not apply
    Checking patch src/Plugin/GeofieldProximitySource/GeocodeOrigin.php...
    error: while searching for:
       */
      public function __construct(array $configuration, $plugin_id, $plugin_definition, Geocoder $geocoder, ProviderPluginManager $providerPluginManager, FormatterPluginManager $formatterPluginManager) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
        $this->originAddress = isset($configuration['origin_address']) ? $configuration['origin_address'] : '';
        $this->useAutocomplete = isset($configuration['use_autocomplete']) ? $configuration['use_autocomplete'] : 0;
        $this->geocoder = $geocoder;
        $this->providerPluginManager = $providerPluginManager;
        $this->options = isset($configuration['settings']['options']) ? $configuration['settings']['options'] : '';
        $this->formatterPluginManager = $formatterPluginManager;
        $this->origin = $this->getAddressOrigin($this->originAddress);
        $this->minTerms = isset($configuration['settings']['autocomplete']['min_terms']) ? $configuration['settings']['autocomplete']['min_terms'] : 4;
        $this->delay = isset($configuration['settings']['autocomplete']['delay']) ? $configuration['settings']['autocomplete']['delay'] : 800;
        $this->addressFormat = isset($configuration['settings']['autocomplete']['address_format']) ? $configuration['settings']['autocomplete']['address_format'] : 'default_formatted_address';
      }
    
      /**
    
    error: patch failed: src/Plugin/GeofieldProximitySource/GeocodeOrigin.php:118
    error: src/Plugin/GeofieldProximitySource/GeocodeOrigin.php: patch does not apply
    Checking patch src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php...
    error: while searching for:
       */
      public function __construct(array $configuration, $plugin_id, $plugin_definition, Geocoder $geocoder, ProviderPluginManager $providerPluginManager, FormatterPluginManager $formatterPluginManager) {
        parent::__construct($configuration, $plugin_id, $plugin_definition, $geocoder, $providerPluginManager, $formatterPluginManager);
        $this->useAutocomplete = isset($configuration['use_autocomplete']) ? $configuration['use_autocomplete'] : 1;
      }
    
      /**
    
    error: patch failed: src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php:41
    error: src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php: patch does not apply
    Checking patch src/ProviderPluginManager.php...
    error: while searching for:
       *   The plugins table list.
       */
      public function providersPluginsTableList(array $enabled_provider_ids): array {
        $providers_link = $this->link->generate(t('Geocoder providers configuration page'), Url::fromRoute('entity.geocoder_provider.collection', [], [
          'attributes' => ['target' => '_blank'],
        ]));
    
    
    error: patch failed: src/ProviderPluginManager.php:135
    error: src/ProviderPluginManager.php: patch does not apply
    
  • Status changed to Closed: outdated 5 months ago
  • 🇮🇹Italy itamair

    Most of the Php & Drupal Cs reported here were already solved in the Geocoder latest releases code.

Production build 0.71.5 2024