diff --git a/geocoder.services.yml b/geocoder.services.yml index e67bd626035325dba13fb8b5d90855bc02f6faf1..c16c356025c99b3379e671add93eaccfb4a75cf1 100644 --- a/geocoder.services.yml +++ b/geocoder.services.yml @@ -5,7 +5,7 @@ services: arguments: ['@config.factory','@plugin.manager.geocoder.provider', '@module_handler'] geocoder.http_adapter: - class: Http\Adapter\Guzzle6\Client + class: Psr\Http\Client\ClientInterface arguments: ['@http_client'] plugin.manager.geocoder.provider: diff --git a/modules/geocoder_address/src/AddressService.php b/modules/geocoder_address/src/AddressService.php index aa9233fd68a56ed48e336170e4135a1911d2d9b5..5e15b53b699a1dbbc7ec4c0ea39d1d1fed2da9f0 100644 --- a/modules/geocoder_address/src/AddressService.php +++ b/modules/geocoder_address/src/AddressService.php @@ -12,7 +12,7 @@ use CommerceGuys\Addressing\Formatter\DefaultFormatter; use CommerceGuys\Addressing\Formatter\PostalLabelFormatter; /** - * Class AddressService. + * Generate an AddressService. * * @package Drupal\geocoder_address */ @@ -118,7 +118,6 @@ class AddressService extends ServiceProviderBase { public function addressArrayToGeoString(array $values) { // Make sure the address_array has all values populated. - /** @var \Drupal\address\Element\Address::applyDefaults() */ $values = ElementAddress::applyDefaults($values); // Without a country code this won't work. @@ -128,7 +127,6 @@ class AddressService extends ServiceProviderBase { // Use the Address formatter to create a string ordered appropriately // for the country in the address. - /** @var CommerceGuys\Addressing\Address */ $address = new AddressingAddress(); $address = $address ->withCountryCode($values['country_code']) @@ -139,11 +137,11 @@ class AddressService extends ServiceProviderBase { ->withAddressLine1($values['address_line1']) ->withAddressLine2($values['address_line2']); - $countrycode = isset($values['country_code']) ? $values['country_code'] : NULL; + $countrycode = $values['country_code'] ?? NULL; $langcode = !empty($values['langcode']) ? $values['langcode'] : 'en'; // Get the formatted address. - /** @var CommerceGuys\Addressing\Formatter\PostalLabelFormatter */ + /** @var \CommerceGuys\Addressing\Formatter\PostalLabelFormatter $formatter */ $formatter = $this->getFormatter($langcode, $countrycode, 'postal'); $address_string = $formatter->format($address); diff --git a/modules/geocoder_field/geocoder_field.module b/modules/geocoder_field/geocoder_field.module index d733673390405798d96e82784581fd0ec4bf3055..136d5f948b54b615c52b8799ddfb8cea2be0cdcc 100644 --- a/modules/geocoder_field/geocoder_field.module +++ b/modules/geocoder_field/geocoder_field.module @@ -247,7 +247,7 @@ function geocoder_field_entity_presave(EntityInterface $entity) { // 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'] : '']); + $failure_status_message = t("Unable to geocode '@text'.", ['@text' => $value['value'] ?? '']); $geo_collection = isset($value['value']) ? \Drupal::service('geocoder')->geocode($value['value'], $providers) : NULL; break; diff --git a/modules/geocoder_field/src/Geocoder/Provider/File.php b/modules/geocoder_field/src/Geocoder/Provider/File.php index 5e694ac2ed4742d3ea907289d20fa6022cc2fbe5..800c344378ccb1f93eecfd05d7c8c971f02bc104 100644 --- a/modules/geocoder_field/src/Geocoder/Provider/File.php +++ b/modules/geocoder_field/src/Geocoder/Provider/File.php @@ -46,7 +46,6 @@ class File extends AbstractProvider implements Provider { } } throw new LogicException(sprintf('Could not find geo data in file: "%s".', basename($filename))); - ; } /** @@ -75,11 +74,9 @@ class File extends AbstractProvider implements Provider { } } - list($degrees, $minutes, $seconds) = $coordinate; + [$degrees, $minutes, $seconds] = $coordinate; $sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1; - $value = $sign * ($degrees + $minutes / 60 + $seconds / 3600); - - return $value; + return $sign * ($degrees + $minutes / 60 + $seconds / 3600); } /** diff --git a/modules/geocoder_field/src/PreprocessorPluginManager.php b/modules/geocoder_field/src/PreprocessorPluginManager.php index 331885f8d1d31e0cd6b8345fbbfdbcddb105b0b7..a19552f556e80315c5ad6f5792d80cf641ded117 100644 --- a/modules/geocoder_field/src/PreprocessorPluginManager.php +++ b/modules/geocoder_field/src/PreprocessorPluginManager.php @@ -85,7 +85,7 @@ class PreprocessorPluginManager extends GeocoderPluginManagerBase { $geocoder_fields[$field_name] = [ 'field_name' => $field_name, 'field_value' => $field, - 'weight' => isset($geocoder['weight']) ? $geocoder['weight'] : 0, + 'weight' => $geocoder['weight'] ?? 0, ]; } @@ -121,12 +121,12 @@ class PreprocessorPluginManager extends GeocoderPluginManagerBase { if (isset($source_value[0]) && !isset($source_value[0]['value']) && isset($source_value[0]['target_id'])) { foreach ($source_value as $i => $value) { - $source_value[$i] = isset($value['target_id']) ? $value['target_id'] : ''; + $source_value[$i] = $value['target_id'] ?? ''; } } if (isset($original_value[0]) && !isset($original_value[0]['value']) && isset($original_value[0]['target_id'])) { foreach ($original_value as $i => $value) { - $original_value[$i] = isset($value['target_id']) ? $value['target_id'] : ''; + $original_value[$i] = $value['target_id'] ?? ''; } } diff --git a/src/ConfigurableProviderUsingHandlerWithAdapterBase.php b/src/ConfigurableProviderUsingHandlerWithAdapterBase.php index 1c98fa086041a4df442cd6c320b55f9809f8ddf6..be6decd75a0760c2e82856d8ca4d85a4fe1bb756 100644 --- a/src/ConfigurableProviderUsingHandlerWithAdapterBase.php +++ b/src/ConfigurableProviderUsingHandlerWithAdapterBase.php @@ -11,9 +11,9 @@ use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\geocoder\Traits\ConfigurableProviderTrait; -use Http\Client\HttpClient; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; +use Psr\Http\Client\ClientInterface; /** * Provides a base class for providers using handlers with HTTP adapter. @@ -53,12 +53,12 @@ abstract class ConfigurableProviderUsingHandlerWithAdapterBase extends ProviderU * The Drupal language manager service. * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager * The typed config manager. - * @param \Http\Client\HttpClient $http_adapter + * @param \Psr\Http\Client\ClientInterface $http_adapter * The HTTP adapter. * @param \Drupal\geocoder\GeocoderThrottleInterface $throttle * The Geocoder Throttle service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, TypedConfigManagerInterface $typed_config_manager, HttpClient $http_adapter, GeocoderThrottleInterface $throttle) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, TypedConfigManagerInterface $typed_config_manager, ClientInterface $http_adapter, GeocoderThrottleInterface $throttle) { try { // The typedConfigManager property needs to be set before the constructor, // to prevent its possible exception, and allow the @@ -94,7 +94,7 @@ abstract class ConfigurableProviderUsingHandlerWithAdapterBase extends ProviderU * {@inheritdoc} */ protected function doGeocode($source) { - $this->throttle->waitForAvailability($this->pluginId, isset($this->configuration['throttle']) ? $this->configuration['throttle'] : []); + $this->throttle->waitForAvailability($this->pluginId, $this->configuration['throttle'] ?? []); return parent::doGeocode($source); } @@ -102,7 +102,7 @@ abstract class ConfigurableProviderUsingHandlerWithAdapterBase extends ProviderU * {@inheritdoc} */ protected function doReverse($latitude, $longitude) { - $this->throttle->waitForAvailability($this->pluginId, isset($this->configuration['throttle']) ? $this->configuration['throttle'] : []); + $this->throttle->waitForAvailability($this->pluginId, $this->configuration['throttle'] ?? []); return parent::doReverse($latitude, $longitude); } diff --git a/src/Plugin/Geocoder/Provider/Random.php b/src/Plugin/Geocoder/Provider/Random.php index 77846c15b38b125377f8d2b8c3290e5a065e5997..f15ff9f0ce6524fd027119f557af987b7d64697a 100644 --- a/src/Plugin/Geocoder/Provider/Random.php +++ b/src/Plugin/Geocoder/Provider/Random.php @@ -80,7 +80,7 @@ class Random extends ProviderBase { return $value; } - return isset($value[$type]) ? $value[$type] : $value; + return $value[$type] ?? $value; } /** diff --git a/src/Plugin/GeofieldProximitySource/GeocodeOrigin.php b/src/Plugin/GeofieldProximitySource/GeocodeOrigin.php index f1f9b7ea3d76d214b74ff7d193874922a1939ecd..880e0ed58e29382ce72a0f0484b45c263c442510 100644 --- a/src/Plugin/GeofieldProximitySource/GeocodeOrigin.php +++ b/src/Plugin/GeofieldProximitySource/GeocodeOrigin.php @@ -118,16 +118,16 @@ class GeocodeOrigin extends GeofieldProximitySourceBase implements ContainerFact */ 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->originAddress = $configuration['origin_address'] ?? ''; + $this->useAutocomplete = $configuration['use_autocomplete'] ?? 0; $this->geocoder = $geocoder; $this->providerPluginManager = $providerPluginManager; - $this->options = isset($configuration['settings']['options']) ? $configuration['settings']['options'] : ''; + $this->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'; + $this->minTerms = $configuration['settings']['autocomplete']['min_terms'] ?? 4; + $this->delay = $configuration['settings']['autocomplete']['delay'] ?? 800; + $this->addressFormat = $configuration['settings']['autocomplete']['address_format'] ?? 'default_formatted_address'; } /** @@ -207,7 +207,7 @@ class GeocodeOrigin extends GeofieldProximitySourceBase implements ContainerFact 'geocoder/general', ]; - $plugins_settings = isset($this->configuration['plugins']) ? $this->configuration['plugins'] : []; + $plugins_settings = $this->configuration['plugins'] ?? []; // Get the enabled/selected plugins. $enabled_plugins = []; @@ -332,7 +332,7 @@ class GeocodeOrigin extends GeofieldProximitySourceBase implements ContainerFact */ public function getEnabledProviderPlugins() { $geocoder_plugins = $this->providerPluginManager->getPlugins(); - $plugins_settings = isset($this->configuration['plugins']) ? $this->configuration['plugins'] : []; + $plugins_settings = $this->configuration['plugins'] ?? []; // Filter out unchecked plugins. $provider_plugin_ids = array_filter($plugins_settings, function ($plugin) { diff --git a/src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php b/src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php index 64481f57156df4183555a384e74b1a2a0e6bd860..7ef1ae10f8c66bb576375701c0af4a8fc6c95c09 100644 --- a/src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php +++ b/src/Plugin/GeofieldProximitySource/deprecated/GeocodeOriginAutocomplete.php @@ -41,7 +41,7 @@ class GeocodeOriginAutocomplete extends GeocodeOrigin { */ 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; + $this->useAutocomplete = $configuration['use_autocomplete'] ?? 1; } /** diff --git a/src/ProviderUsingHandlerWithAdapterBase.php b/src/ProviderUsingHandlerWithAdapterBase.php index 64a21849d8196aca2448d012684f9c239f016b28..a32d0062a984822b73b132224534a344fbc20fa7 100644 --- a/src/ProviderUsingHandlerWithAdapterBase.php +++ b/src/ProviderUsingHandlerWithAdapterBase.php @@ -5,7 +5,7 @@ namespace Drupal\geocoder; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -16,7 +16,7 @@ abstract class ProviderUsingHandlerWithAdapterBase extends ProviderUsingHandlerB /** * The HTTP adapter. * - * @var \Http\Client\HttpClient + * @var \Psr\Http\Client\ClientInterface */ protected $httpAdapter; @@ -35,12 +35,12 @@ abstract class ProviderUsingHandlerWithAdapterBase extends ProviderUsingHandlerB * The cache backend used to cache geocoding data. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The Drupal language manager service. - * @param \Http\Client\HttpClient $http_adapter + * @param \Psr\Http\Client\ClientInterface $http_adapter * The HTTP adapter. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, HttpClient $http_adapter) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ClientInterface $http_adapter) { parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $cache_backend, $language_manager); $this->httpAdapter = $http_adapter; }