diff --git a/geolocation.views.inc b/geolocation.views.inc index 1f57cf3a78edc4cb7881fc913b60404395e6f25e..fce5044718ef4ca294ff6a1ea0a704c761747f5d 100644 --- a/geolocation.views.inc +++ b/geolocation.views.inc @@ -23,12 +23,11 @@ function geolocation_field_views_data(FieldStorageConfigInterface $field_storage $title_short = $help = ''; - if ($table_mapping = $entity_storage->getTableMapping()) { - $field_table_name = $table_mapping->getFieldTableName($field_storage->getName()); - if (!empty($data[$field_table_name][$field_storage->getName()])) { - $title_short = $data[$field_table_name][$field_storage->getName()]['title short']; - $help = $data[$field_table_name][$field_storage->getName()]['help']; - } + $table_mapping = $entity_storage->getTableMapping(); + $field_table_name = $table_mapping->getFieldTableName($field_storage->getName()); + if (!empty($data[$field_table_name][$field_storage->getName()])) { + $title_short = $data[$field_table_name][$field_storage->getName()]['title short']; + $help = $data[$field_table_name][$field_storage->getName()]['help']; } $args = ['@field_name' => $field_storage->getName()]; diff --git a/modules/geolocation_baidu/geolocation_baidu.install b/modules/geolocation_baidu/geolocation_baidu.install index 46173bbeb2718a6820a8847c5f405b5162d6c3e7..3a894899ebc3e3de1910269974ebfb66f0a6910a 100644 --- a/modules/geolocation_baidu/geolocation_baidu.install +++ b/modules/geolocation_baidu/geolocation_baidu.install @@ -8,11 +8,9 @@ use Drupal\Core\Url; /** - * {@inheritdoc} - * * Implements hook_requirements(). */ -function geolocation_baidu_requirements($phase) { +function geolocation_baidu_requirements(string $phase): array { $requirements = []; if ($phase == 'runtime') { $requirements['geolocation_baidu_api_key'] = [ @@ -35,6 +33,6 @@ function geolocation_baidu_requirements($phase) { /** * Implements hook_requirements(). */ -function geolocation_baidu_uninstall() { +function geolocation_baidu_uninstall(): void { Drupal::configFactory()->getEditable('baidu_maps.settings')->delete(); } diff --git a/modules/geolocation_baidu/src/Form/BaiduMapsSettings.php b/modules/geolocation_baidu/src/Form/BaiduMapsSettings.php index c68a0482e858c2aca6914d0c1f33c767848b74f1..049aeb2911599e59dbbcb731fafb65162e72a322 100644 --- a/modules/geolocation_baidu/src/Form/BaiduMapsSettings.php +++ b/modules/geolocation_baidu/src/Form/BaiduMapsSettings.php @@ -15,14 +15,14 @@ class BaiduMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { + public function buildForm(array $form, FormStateInterface $form_state): array { $config = $this->configFactory->get('baidu_maps.settings'); $form['key'] = [ '#type' => 'textfield', '#title' => $this->t('Baidu Maps App ID'), '#default_value' => $config->get('key'), - '#description' => $this->t('Baidu Maps requires users to sign up at <a href="https://http://lbsyun.baidu.com">http://lbsyun.baidu.com</a>.'), + '#description' => $this->t('Baidu Maps requires users to sign up at <a href="https://lbsyun.baidu.com">https://lbsyun.baidu.com</a>.'), ]; return parent::buildForm($form, $form_state); @@ -31,14 +31,14 @@ class BaiduMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function getFormId() { + public function getFormId(): string { return 'geolocation_baidu_settings'; } /** * {@inheritdoc} */ - protected function getEditableConfigNames() { + protected function getEditableConfigNames(): array { return [ 'baidu_maps.settings', ]; @@ -47,7 +47,7 @@ class BaiduMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $config = $this->configFactory()->getEditable('baidu_maps.settings'); $config->set('key', $form_state->getValue('key')); diff --git a/modules/geolocation_bing/geolocation_bing.install b/modules/geolocation_bing/geolocation_bing.install index 5d19661939d8c80e966432adcaa7065b71659adf..69bce957b1d3ef37eb70ddf746d3795fbed3c1d6 100644 --- a/modules/geolocation_bing/geolocation_bing.install +++ b/modules/geolocation_bing/geolocation_bing.install @@ -8,11 +8,9 @@ use Drupal\Core\Url; /** - * {@inheritdoc} - * * Implements hook_requirements(). */ -function geolocation_bing_requirements($phase) { +function geolocation_bing_requirements(string $phase): array { $requirements = []; if ($phase == 'runtime') { $requirements['geolocation_bing_api_key'] = [ @@ -35,6 +33,6 @@ function geolocation_bing_requirements($phase) { /** * Implements hook_requirements(). */ -function geolocation_bing_uninstall() { +function geolocation_bing_uninstall(): void { Drupal::configFactory()->getEditable('bing_maps.settings')->delete(); } diff --git a/modules/geolocation_demo/config/optional/block.block.geolocationdemo.yml b/modules/geolocation_demo/config/optional/block.block.geolocationdemo.yml deleted file mode 100644 index 0a90e90aba830c962bc7126c256a48250d51c830..0000000000000000000000000000000000000000 --- a/modules/geolocation_demo/config/optional/block.block.geolocationdemo.yml +++ /dev/null @@ -1,23 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - system.menu.geolocation-demo - module: - - system - enforced: - module: - - geolocation_demo -id: geolocationdemo -region: sidebar_first -weight: 0 -provider: null -plugin: 'system_menu_block:geolocation-demo' -settings: - id: 'system_menu_block:geolocation-demo' - label: 'Geolocation Demo' - provider: system - label_display: visible - level: 1 - depth: 0 -visibility: { } diff --git a/modules/geolocation_demo/src/Form/DemoWidget.php b/modules/geolocation_demo/src/Form/DemoWidget.php index 8741b3d41ecfebd071680201204e5ccd45216871..68129e4bad22ba0abb8b77e9b0daae781c3e45f1 100644 --- a/modules/geolocation_demo/src/Form/DemoWidget.php +++ b/modules/geolocation_demo/src/Form/DemoWidget.php @@ -18,14 +18,14 @@ abstract class DemoWidget extends FormBase { * * @var \Drupal\Core\Field\WidgetPluginManager */ - protected $pluginManagerFieldWidget; + protected WidgetPluginManager $pluginManagerFieldWidget; /** * Drupal\Core\Entity\EntityTypeManager definition. * * @var \Drupal\Core\Entity\EntityTypeManager */ - protected $entityTypeManager; + protected EntityTypeManager $entityTypeManager; /** * {@inheritdoc} @@ -37,6 +37,8 @@ abstract class DemoWidget extends FormBase { /** * {@inheritdoc} + * + * @phpstan-ignore-next-line */ public static function create(ContainerInterface $container) { return new static( @@ -46,9 +48,19 @@ abstract class DemoWidget extends FormBase { } /** - * {@inheritdoc} + * Get widget form. + * + * @param string $widget_id + * Widget ID. + * @param array $form + * Form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. + * + * @return array + * Widget form. */ - public function getWidgetForm($widget_id, array $form, FormStateInterface $form_state) { + public function getWidgetForm(string $widget_id, array $form, FormStateInterface $form_state): array { /** @var \Drupal\node\NodeInterface $node */ $node = $this->entityTypeManager->getStorage('node')->create([ @@ -82,6 +94,6 @@ abstract class DemoWidget extends FormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state): void {} } diff --git a/modules/geolocation_geometry/geolocation_geometry.install b/modules/geolocation_geometry/geolocation_geometry.install index ca4e61f5ed61bc53d465f6d1f4851356b7f5bdfa..ac04619f27c912626233c97c0b4ebe857e1266f6 100644 --- a/modules/geolocation_geometry/geolocation_geometry.install +++ b/modules/geolocation_geometry/geolocation_geometry.install @@ -8,7 +8,7 @@ /** * Implements hook_requirements(). */ -function geolocation_geometry_requirements($phase): array { +function geolocation_geometry_requirements(string $phase): array { $requirements = []; $requirements['geolocation_geometry_database_compatibility'] = [ 'title' => t('Geolocation Geometry - Database Compatibility'), diff --git a/modules/geolocation_geometry/geolocation_geometry.views.inc b/modules/geolocation_geometry/geolocation_geometry.views.inc index a2a4e68fde3a2202ee4641a92151b45e9fe5f7c8..7c52472a23fdae8532125eef45520dd9b017bca9 100644 --- a/modules/geolocation_geometry/geolocation_geometry.views.inc +++ b/modules/geolocation_geometry/geolocation_geometry.views.inc @@ -37,6 +37,7 @@ function geolocation_geometry_field_views_data(FieldStorageConfigInterface $fiel $geometry_fields[$geometry_field_id]['field_type'] = $field_type; $geometry_fields[$geometry_field_id]['entity_type'] = $entity_type; $geometry_fields[$geometry_field_id]['entity_id_field'] = $entity_definition->getKey('id'); + // @phpstan-ignore-next-line $geometry_fields[$geometry_field_id]['entity_data_table'] = $entity_table_mapping->getDataTable(); $geometry_fields[$geometry_field_id]['entity_label'] = $entity_label; $geometry_fields[$geometry_field_id]['geometry_field_name'] = $geometry_field_name; @@ -225,6 +226,7 @@ function geolocation_geometry_field_views_data_views_data_alter(array &$data, Fi 'field_type' => $field_storage->getType(), 'entity_type' => $entity_type, 'entity_id_field' => $entity_definition->getKey('id'), + // @phpstan-ignore-next-line 'entity_data_table' => $entity_table_mapping->getDataTable(), 'entity_label' => $entity_label, 'geometry_field_name' => $field_storage->getName(), @@ -233,6 +235,7 @@ function geolocation_geometry_field_views_data_views_data_alter(array &$data, Fi foreach (\Drupal::service('entity_field.manager')->getFieldMapByFieldType('geolocation') as $entity_type => $geolocation_fields) { /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $geolocation_table_mapping */ + // @phpstan-ignore-next-line $geolocation_table_mapping = \Drupal::entityTypeManager()->getStorage($entity_type)->getTableMapping(); foreach ($geolocation_fields as $geolocation_field_name => $geolocation_field_data) { diff --git a/modules/geolocation_geometry/modules/geolocation_geometry_demo/geolocation_geometry_demo.install b/modules/geolocation_geometry/modules/geolocation_geometry_demo/geolocation_geometry_demo.install index fca9747b9b874be2849aafbef480b78840c644f1..f932e8351f1c98adb1c372a0bd5af26dbae683b3 100644 --- a/modules/geolocation_geometry/modules/geolocation_geometry_demo/geolocation_geometry_demo.install +++ b/modules/geolocation_geometry/modules/geolocation_geometry_demo/geolocation_geometry_demo.install @@ -68,7 +68,7 @@ function geolocation_geometry_demo_install(): void { /** * Implements hook_uninstall(). */ -function geolocation_geometry_demo_uninstall() { +function geolocation_geometry_demo_uninstall(): void { $node_storage = \Drupal::entityTypeManager()->getStorage('node'); $node_storage->delete($node_storage->loadByProperties(['type' => 'geolocation_geometry_demo'])); diff --git a/modules/geolocation_geometry/src/GeometryFormat/GeoJSON.php b/modules/geolocation_geometry/src/GeometryFormat/GeoJSON.php index 74f1816074bde5f701f9b8a14f44e72e5a0702a6..7340695b61c27ddc5955e374fcb967ec49201b64 100644 --- a/modules/geolocation_geometry/src/GeometryFormat/GeoJSON.php +++ b/modules/geolocation_geometry/src/GeometryFormat/GeoJSON.php @@ -29,7 +29,7 @@ class GeoJSON implements GeometryFormatInterface { $json = json_decode($text); if (is_object($json->geometry ?? FALSE)) { - return static::geometryByText($json->geometry); + return static::geometryByText((string) $json->geometry); } if (!is_string($json->type ?? FALSE)) { diff --git a/modules/geolocation_geometry/src/GeometryType/GeometryCollection.php b/modules/geolocation_geometry/src/GeometryType/GeometryCollection.php index 6ff5c612d97d51f19916e78e5d2fb974becbcb51..f041494a1b4948f8f295dce00da617d07165e1e8 100644 --- a/modules/geolocation_geometry/src/GeometryType/GeometryCollection.php +++ b/modules/geolocation_geometry/src/GeometryType/GeometryCollection.php @@ -10,7 +10,7 @@ class GeometryCollection extends Collection { /** * Constructor. */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct(); foreach ($components as $comp) { diff --git a/modules/geolocation_geometry/src/GeometryType/LineString.php b/modules/geolocation_geometry/src/GeometryType/LineString.php index b3b3f6edc9efd338b09df39fd84ac91217710751..a7f1ccd0ed76e6842ea0e68f96842ceb542e3ead 100644 --- a/modules/geolocation_geometry/src/GeometryType/LineString.php +++ b/modules/geolocation_geometry/src/GeometryType/LineString.php @@ -12,7 +12,7 @@ class LineString extends MultiPoint { /** * Constructor. */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct($components); if (count($components) < 2) { diff --git a/modules/geolocation_geometry/src/GeometryType/LinearRing.php b/modules/geolocation_geometry/src/GeometryType/LinearRing.php index 41c46a6d69e63559d8ed92529c4e67db55e15b77..42826c6730f3f4aeb2bb3beae89b790d96384081 100644 --- a/modules/geolocation_geometry/src/GeometryType/LinearRing.php +++ b/modules/geolocation_geometry/src/GeometryType/LinearRing.php @@ -12,7 +12,7 @@ class LinearRing extends LineString { /** * Constructor. */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct($components); if (!(reset($components)->equals(end($components)))) { diff --git a/modules/geolocation_geometry/src/GeometryType/MultiLineString.php b/modules/geolocation_geometry/src/GeometryType/MultiLineString.php index 484986b0a433e34b7046f1dcc96f88ea7ad36ff3..1a3c8d36c07df5ac81ad288abcf53b5635551bc8 100644 --- a/modules/geolocation_geometry/src/GeometryType/MultiLineString.php +++ b/modules/geolocation_geometry/src/GeometryType/MultiLineString.php @@ -10,7 +10,7 @@ class MultiLineString extends Collection { /** * Constructor. */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct(); foreach ($components as $comp) { diff --git a/modules/geolocation_geometry/src/GeometryType/MultiPoint.php b/modules/geolocation_geometry/src/GeometryType/MultiPoint.php index 609434f78b47b739841816d28e187e40dc0a9212..c7a967988365c2eb4cc1a146cb132eb33c05a954 100644 --- a/modules/geolocation_geometry/src/GeometryType/MultiPoint.php +++ b/modules/geolocation_geometry/src/GeometryType/MultiPoint.php @@ -12,7 +12,7 @@ class MultiPoint extends Collection { /** * Constructor. */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct(); foreach ($components as $comp) { diff --git a/modules/geolocation_geometry/src/GeometryType/MultiPolygon.php b/modules/geolocation_geometry/src/GeometryType/MultiPolygon.php index c22368b302c282c8e798104c8a225af720e69fe6..f27f3246578ef158d46d7fce575341f15e0c82cf 100644 --- a/modules/geolocation_geometry/src/GeometryType/MultiPolygon.php +++ b/modules/geolocation_geometry/src/GeometryType/MultiPolygon.php @@ -12,7 +12,7 @@ class MultiPolygon extends Collection { /** * Constructor. */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct(); foreach ($components as $comp) { diff --git a/modules/geolocation_geometry/src/GeometryType/Polygon.php b/modules/geolocation_geometry/src/GeometryType/Polygon.php index 15c6361da4192a57484b52844b23ead56009803c..6f23f0060a797405f1d9d98be16a7cca449cb404 100644 --- a/modules/geolocation_geometry/src/GeometryType/Polygon.php +++ b/modules/geolocation_geometry/src/GeometryType/Polygon.php @@ -12,7 +12,7 @@ class Polygon extends Collection { /** * {@inheritdoc} */ - public function __construct($components) { + public function __construct(array $components) { parent::__construct(); $outer = $components[0]; diff --git a/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryDataFormatter.php b/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryDataFormatter.php index dbfe80a13db9c23131f120f43822a733c6c90070..0c2ff3f38bd06038b979d25240d9934736eb8c45 100644 --- a/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryDataFormatter.php +++ b/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryDataFormatter.php @@ -72,6 +72,7 @@ class GeolocationGeometryDataFormatter extends FormatterBase { $summary[] = $this->t( 'Data format: @format', [ + // @phpstan-ignore-next-line '@format' => match($settings['geometry_format']) { 'geojson' => $this->t('GeoJSON'), 'wkt' => $this->t('WKT (Well Known Text)'), diff --git a/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryFileFormatter.php b/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryFileFormatter.php index 6d20a532a641ad71b6ee8c3012736fd39e7e4d4a..ac1203f06af84800dc789efd300d11316fa17719 100644 --- a/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryFileFormatter.php +++ b/modules/geolocation_geometry/src/Plugin/Field/FieldFormatter/GeolocationGeometryFileFormatter.php @@ -79,6 +79,7 @@ class GeolocationGeometryFileFormatter extends FormatterBase { $summary[] = $this->t( 'Data format: @format', [ + // @phpstan-ignore-next-line '@format' => match($settings['geometry_format']) { 'geojson' => $this->t('GeoJSON'), 'wkt' => $this->t('WKT (Well Known Text)'), @@ -106,6 +107,7 @@ class GeolocationGeometryFileFormatter extends FormatterBase { '#title' => $this->t( 'Download %type file', [ + // @phpstan-ignore-next-line '%type' => match($settings['geometry_format']) { 'geojson' => $this->t('GeoJSON'), 'wkt' => $this->t('WKT (Well Known Text)'), diff --git a/modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryBase.php b/modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryBase.php index 917f06060c0d2ef0b5cc7bfe4307e20b9de6ab6c..35bdeecdc65838ac248876f7414f50579109a6a3 100644 --- a/modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryBase.php +++ b/modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryBase.php @@ -73,14 +73,14 @@ abstract class GeolocationGeometryBase extends FieldItemBase { /** * {@inheritdoc} */ - public function postSave($update): void { + public function postSave($update): bool { parent::postSave($update); $entity = $this->getEntity(); $entity_storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId()); if (!is_a($entity_storage, '\Drupal\Core\Entity\Sql\SqlContentEntityStorage')) { - return; + return FALSE; } /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $entity_storage */ @@ -89,6 +89,7 @@ abstract class GeolocationGeometryBase extends FieldItemBase { if ($entity->getEntityType()->isRevisionable()) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ + // @phpstan-ignore-next-line $revision_query = \Drupal::database()->update($table_mapping->getDedicatedRevisionTableName($field_storage_definition)); $revision_query->expression($field_storage_definition->getName() . '_geometry', 'ST_GeomFromGeoJSON(' . $field_storage_definition->getName() . '_geojson)'); @@ -102,6 +103,7 @@ abstract class GeolocationGeometryBase extends FieldItemBase { $revision_query->execute(); } + // @phpstan-ignore-next-line $query = \Drupal::database()->update($table_mapping->getDedicatedDataTableName($field_storage_definition)); $query->expression($field_storage_definition->getName() . '_geometry', 'ST_GeomFromGeoJSON(' . $field_storage_definition->getName() . '_geojson)'); @@ -112,6 +114,8 @@ abstract class GeolocationGeometryBase extends FieldItemBase { $query->condition('bundle', $entity->bundle()); $query->condition('delta', $this->getName()); $query->execute(); + + return FALSE; } /** @@ -167,7 +171,7 @@ abstract class GeolocationGeometryBase extends FieldItemBase { $center_point = ['latitude' => 0, 'longitude' => 0]; } return atan2($coordinate1['latitude'] - $center_point['latitude'], $coordinate1['longitude'] - $center_point['longitude']) * 180 / M_PI > - atan2($coordinate2['latitude'] - $center_point['latitude'], $coordinate2['longitude'] - $center_point['longitude']) * 180 / M_PI; + atan2($coordinate2['latitude'] - $center_point['latitude'], $coordinate2['longitude'] - $center_point['longitude']) * 180 / M_PI ? 1 : -1; } /** diff --git a/modules/geolocation_geometry/src/Plugin/Field/FieldWidget/GeolocationGeometryGeoJsonWidget.php b/modules/geolocation_geometry/src/Plugin/Field/FieldWidget/GeolocationGeometryGeoJsonWidget.php index 342412698778f6ef2a358349e98d41e7fce25524..dcaf065da25e67f2537ad21a09d21c2fde1f45d7 100644 --- a/modules/geolocation_geometry/src/Plugin/Field/FieldWidget/GeolocationGeometryGeoJsonWidget.php +++ b/modules/geolocation_geometry/src/Plugin/Field/FieldWidget/GeolocationGeometryGeoJsonWidget.php @@ -31,7 +31,7 @@ class GeolocationGeometryGeoJsonWidget extends WidgetBase { /** * {@inheritdoc} */ - public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { + public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state): array { $description_link = Link::fromTextAndUrl($this->t('GeoJSON data'), Url::fromUri('//en.wikipedia.org/wiki/GeoJSON', ['attributes' => ['target' => '_blank']]))->toString(); diff --git a/modules/geolocation_geometry/src/Plugin/Validation/Constraint/GeometryConstraintValidator.php b/modules/geolocation_geometry/src/Plugin/Validation/Constraint/GeometryConstraintValidator.php index 7557a56ced624e226b8a0251e9d9f2491ba3d0cb..427b7f18bd5f86ad129d150268ecb9f830f880bd 100755 --- a/modules/geolocation_geometry/src/Plugin/Validation/Constraint/GeometryConstraintValidator.php +++ b/modules/geolocation_geometry/src/Plugin/Validation/Constraint/GeometryConstraintValidator.php @@ -15,7 +15,7 @@ class GeometryConstraintValidator extends ConstraintValidator { /** * {@inheritdoc} */ - public function validate($value, Constraint $constraint): void { + public function validate(mixed $value, Constraint $constraint): void { if (!is_a($constraint, GeometryConstraint::class)) { return; @@ -28,12 +28,10 @@ class GeometryConstraintValidator extends ConstraintValidator { switch (strtolower($constraint->type)) { case 'wkt': - /** @var \Drupal\geolocation_geometry\GeometryType\GeometryTypeInterface $geometry */ $geometry = WKT::geometryByText($value); break; case 'geojson': - /** @var \Drupal\geolocation_geometry\GeometryType\GeometryTypeInterface $geometry */ $geometry = GeoJSON::geometryByText($value); break; diff --git a/modules/geolocation_geometry/src/Plugin/geolocation/DataProvider/GeolocationGeometry.php b/modules/geolocation_geometry/src/Plugin/geolocation/DataProvider/GeolocationGeometry.php index dc6c367fd5a7fd363a9a4d5cf82dd2aae08b15b8..3e2bd34e726b10d34034980c22ef19c9ed719b07 100644 --- a/modules/geolocation_geometry/src/Plugin/geolocation/DataProvider/GeolocationGeometry.php +++ b/modules/geolocation_geometry/src/Plugin/geolocation/DataProvider/GeolocationGeometry.php @@ -131,10 +131,7 @@ class GeolocationGeometry extends DataProviderBase implements DataProviderInterf $current_style = $viewsField->displayHandler->getPlugin('style'); - if ( - empty($current_style) - || !is_subclass_of($current_style, 'Drupal\geolocation\Plugin\views\style\GeolocationStyleBase') - ) { + if (!is_subclass_of($current_style, 'Drupal\geolocation\Plugin\views\style\GeolocationStyleBase')) { return $locations; } @@ -161,10 +158,7 @@ class GeolocationGeometry extends DataProviderBase implements DataProviderInterf $current_style = $viewsField->displayHandler->getPlugin('style'); - if ( - empty($current_style) - || !is_subclass_of($current_style, 'Drupal\geolocation\Plugin\views\style\GeolocationStyleBase') - ) { + if (!is_subclass_of($current_style, 'Drupal\geolocation\Plugin\views\style\GeolocationStyleBase')) { return $shapes; } diff --git a/modules/geolocation_geometry/src/Plugin/views/argument/GeoProximityArgument.php b/modules/geolocation_geometry/src/Plugin/views/argument/GeoProximityArgument.php index 378d048911198b81c5861942dcc67c1c9232f019..b9aa003ff42aca374002534cb4da1116530ca772 100644 --- a/modules/geolocation_geometry/src/Plugin/views/argument/GeoProximityArgument.php +++ b/modules/geolocation_geometry/src/Plugin/views/argument/GeoProximityArgument.php @@ -22,7 +22,7 @@ class GeoProximityArgument extends ProximityArgument { /** * {@inheritdoc} */ - public function getFormula() { + public function getFormula(): ?string { // Parse argument for reference location. $values = $this->getParsedReferenceLocation(); // Make sure we have enough information to start with. @@ -42,9 +42,8 @@ class GeoProximityArgument extends ProximityArgument { return !empty($formula) ? str_replace('***table***', $this->tableAlias, $formula) : FALSE; } - else { - return FALSE; - } + + return NULL; } } diff --git a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationContains.php b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationContains.php index fbe6c539a711b35d526710e2a937385a9245990e..5d132f77bae80685e6b4ce2a1b51a13783b0a5df 100644 --- a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationContains.php +++ b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationContains.php @@ -16,10 +16,15 @@ class GeolocationContains extends JoinPluginBase implements JoinPluginInterface /** * {@inheritdoc} + * + * @param \Drupal\Core\Database\Query\SelectInterface $select_query + * Select query. + * @param array $table + * Table data. + * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query + * View query. */ public function buildJoin($select_query, $table, $view_query): void { - /** @var \Drupal\Core\Database\Query\Select $select_query */ - $geometry_field = $table['alias'] . '.' . $this->field . '_geometry'; $latitude_field = $this->leftTable . '.' . $this->leftField . '_lat'; $longitude_field = $this->leftTable . '.' . $this->leftField . '_lng'; diff --git a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryContains.php b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryContains.php index 22bc1ef91ebf55abe8bfd3b9863ce4b8323f5925..cc4cdc13d16c9836ff010b2b2c81fd2561f1c3e6 100644 --- a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryContains.php +++ b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryContains.php @@ -16,6 +16,13 @@ class GeolocationGeometryContains extends JoinPluginBase implements JoinPluginIn /** * {@inheritdoc} + * + * @param \Drupal\Core\Database\Query\SelectInterface $select_query + * Select query. + * @param array $table + * Table data. + * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query + * View query. */ public function buildJoin($select_query, $table, $view_query): void { /** @var \Drupal\Core\Database\Query\Select $select_query */ diff --git a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryIntersects.php b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryIntersects.php index 414cef4a01d77d6dbc9ef07e25ad678d8f8054e6..4f42c9ac06565acc1063e186b5c69abd2a6386c9 100644 --- a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryIntersects.php +++ b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryIntersects.php @@ -16,6 +16,13 @@ class GeolocationGeometryIntersects extends JoinPluginBase implements JoinPlugin /** * {@inheritdoc} + * + * @param \Drupal\Core\Database\Query\SelectInterface $select_query + * Select query. + * @param array $table + * Table data. + * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query + * View query. */ public function buildJoin($select_query, $table, $view_query): void { /** @var \Drupal\Core\Database\Query\Select $select_query */ diff --git a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryWithin.php b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryWithin.php index 2528fec551ffa58e658e22bfd37adf264f2929fc..2bc1847b8d7706e1498d398c52931f3bc1d95d1b 100644 --- a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryWithin.php +++ b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationGeometryWithin.php @@ -16,6 +16,13 @@ class GeolocationGeometryWithin extends JoinPluginBase implements JoinPluginInte /** * {@inheritdoc} + * + * @param \Drupal\Core\Database\Query\SelectInterface $select_query + * Select query. + * @param array $table + * Table data. + * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query + * View query. */ public function buildJoin($select_query, $table, $view_query): void { /** @var \Drupal\Core\Database\Query\Select $select_query */ diff --git a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationIntersects.php b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationIntersects.php index f1daefa9c3ee2e1f7fd2f3e2af7e56d16bfd0111..f58a9d56efc3b34269ef561d9a8a40b4d8f26793 100644 --- a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationIntersects.php +++ b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationIntersects.php @@ -16,6 +16,13 @@ class GeolocationIntersects extends JoinPluginBase implements JoinPluginInterfac /** * {@inheritdoc} + * + * @param \Drupal\Core\Database\Query\SelectInterface $select_query + * Select query. + * @param array $table + * Table data. + * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query + * View query. */ public function buildJoin($select_query, $table, $view_query): void { /** @var \Drupal\Core\Database\Query\Select $select_query */ diff --git a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationWithin.php b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationWithin.php index 93ccc070f377d07089d3c140f21a71fd756735a4..6ee8b3d7e05df645db552d067c07933bb009b752 100644 --- a/modules/geolocation_geometry/src/Plugin/views/join/GeolocationWithin.php +++ b/modules/geolocation_geometry/src/Plugin/views/join/GeolocationWithin.php @@ -16,6 +16,13 @@ class GeolocationWithin extends JoinPluginBase implements JoinPluginInterface { /** * {@inheritdoc} + * + * @param \Drupal\Core\Database\Query\SelectInterface $select_query + * Select query. + * @param array $table + * Table data. + * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query + * View query. */ public function buildJoin($select_query, $table, $view_query): void { /** @var \Drupal\Core\Database\Query\Select $select_query */ diff --git a/modules/geolocation_geometry/src/Plugin/views/relationship/GeolocationGeometry.php b/modules/geolocation_geometry/src/Plugin/views/relationship/GeolocationGeometry.php index b39cce314a3a954afbb413509cb28a79eb12936a..a0de5a5e150f321d62e2604b3019f27191c5afa4 100644 --- a/modules/geolocation_geometry/src/Plugin/views/relationship/GeolocationGeometry.php +++ b/modules/geolocation_geometry/src/Plugin/views/relationship/GeolocationGeometry.php @@ -64,6 +64,11 @@ class GeolocationGeometry extends RelationshipPluginBase { /** * {@inheritdoc} + * + * @param array $form + * Form render array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); diff --git a/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryFieldTest.php b/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryFieldTest.php index 0ce9c18dddff22adf9bcda44569a329b012cc331..40de83dde73afee840de07619dd4044f53523277 100644 --- a/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryFieldTest.php +++ b/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryFieldTest.php @@ -29,7 +29,7 @@ class GeolocationGeometryFieldTest extends BrowserTestBase { /** * Test user. * - * @var \Drupal\user\Entity\User|false + * @var \Drupal\user\Entity\User */ protected User $articleCreator; @@ -74,7 +74,7 @@ class GeolocationGeometryFieldTest extends BrowserTestBase { /** * Test GeoJSON to WKT. */ - public function testGeojsonToWkt() { + public function testGeojsonToWkt(): void { EntityFormDisplay::load('node.geolocation_geometry_demo.default') ->setComponent('field_geolocation_geometry_polyg', [ 'type' => 'geolocation_geometry_geojson', @@ -107,7 +107,7 @@ class GeolocationGeometryFieldTest extends BrowserTestBase { /** * Test WKT to GeoJSON. */ - public function testWktToGeojson() { + public function testWktToGeojson(): void { EntityFormDisplay::load('node.geolocation_geometry_demo.default') ->setComponent('field_geolocation_geometry_polyg', [ 'type' => 'geolocation_geometry_wkt', diff --git a/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryViewsBoundaryTest.php b/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryViewsBoundaryTest.php index 894f2e27713e2968e79e977c859a3a84c4bce8d2..7e9654e6213e1437573205cc22720e82d8ec795e 100644 --- a/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryViewsBoundaryTest.php +++ b/modules/geolocation_geometry/tests/src/Functional/GeolocationGeometryViewsBoundaryTest.php @@ -30,14 +30,14 @@ class GeolocationGeometryViewsBoundaryTest extends BrowserTestBase { * * @var array */ - public static $testViews = ['geolocation_geometry_test_boundary']; + public static array $testViews = ['geolocation_geometry_test_boundary']; /** * ID of the geolocation field in this test. * * @var string */ - protected $viewsPath = 'geolocation-geometry-test-boundary'; + protected string $viewsPath = 'geolocation-geometry-test-boundary'; /** * {@inheritdoc} @@ -56,7 +56,7 @@ class GeolocationGeometryViewsBoundaryTest extends BrowserTestBase { /** * Tests the boundary filter. */ - public function testBoundaryNoLocations() { + public function testBoundaryNoLocations(): void { $this->drupalGet($this->viewsPath); $this->assertSession()->statusCodeEquals(200); } @@ -66,7 +66,7 @@ class GeolocationGeometryViewsBoundaryTest extends BrowserTestBase { * * It's currently locked to filter boundary of NE80,80 to SW20,20. */ - public function testBoundaryLocations() { + public function testBoundaryLocations(): void { $entity_test_storage = \Drupal::entityTypeManager()->getStorage('node'); $entity_test_storage->create([ diff --git a/modules/geolocation_google_maps/geolocation_google_maps.install b/modules/geolocation_google_maps/geolocation_google_maps.install index edf645f6da175eb1976341ac238b28c9a330a788..b32db49e14cc3e3427758b35b3b9d4209835313b 100644 --- a/modules/geolocation_google_maps/geolocation_google_maps.install +++ b/modules/geolocation_google_maps/geolocation_google_maps.install @@ -8,11 +8,9 @@ use Drupal\Core\Url; /** - * {@inheritdoc} - * * Implements hook_requirements(). */ -function geolocation_google_maps_requirements($phase) { +function geolocation_google_maps_requirements(string $phase): array { $requirements = []; if ($phase == 'runtime') { $requirements['geolocation_google_maps_api_key'] = [ @@ -43,6 +41,6 @@ function geolocation_google_maps_requirements($phase) { /** * Implements hook_requirements(). */ -function geolocation_google_maps_uninstall() { +function geolocation_google_maps_uninstall(): void { Drupal::configFactory()->getEditable('geolocation_google_maps.settings')->delete(); } diff --git a/modules/geolocation_google_maps/modules/geolocation_google_maps_demo/geolocation_google_maps_demo.install b/modules/geolocation_google_maps/modules/geolocation_google_maps_demo/geolocation_google_maps_demo.install index e6d317f5afcec105706839cb753be7fa84bce300..8f8ae62c95f6aefe95cd323878df9f050309da8c 100644 --- a/modules/geolocation_google_maps/modules/geolocation_google_maps_demo/geolocation_google_maps_demo.install +++ b/modules/geolocation_google_maps/modules/geolocation_google_maps_demo/geolocation_google_maps_demo.install @@ -8,7 +8,7 @@ /** * Implements hook_install(). */ -function geolocation_google_maps_demo_install() { +function geolocation_google_maps_demo_install(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_google_maps.settings'); if (empty($config->get('google_map_api_key'))) { @@ -19,7 +19,7 @@ function geolocation_google_maps_demo_install() { /** * Implements hook_uninstall(). */ -function geolocation_google_maps_demo_uninstall() { +function geolocation_google_maps_demo_uninstall(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_google_maps.settings'); if ($config->get('google_map_api_key') == 'AIzaSyChy7jQvcJpTpIiupQhq4wacdVzdum3hvc') { diff --git a/modules/geolocation_google_maps/modules/geolocation_google_static_maps/src/Form/GeolocationGoogleStaticMapsSettings.php b/modules/geolocation_google_maps/modules/geolocation_google_static_maps/src/Form/GeolocationGoogleStaticMapsSettings.php index bb104fb225367c8b1d23e455398b89c0d86d0d31..f5451b00dc90d1bcf14e044f9d2c732f05883ec4 100644 --- a/modules/geolocation_google_maps/modules/geolocation_google_static_maps/src/Form/GeolocationGoogleStaticMapsSettings.php +++ b/modules/geolocation_google_maps/modules/geolocation_google_static_maps/src/Form/GeolocationGoogleStaticMapsSettings.php @@ -15,7 +15,7 @@ class GeolocationGoogleStaticMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { + public function buildForm(array $form, FormStateInterface $form_state): array { $config = $this->configFactory->get('geolocation_google_static_maps.settings'); $form['google_static_maps_url_secret'] = [ @@ -47,7 +47,7 @@ class GeolocationGoogleStaticMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $config = $this->configFactory()->getEditable('geolocation_google_static_maps.settings'); $config->set('google_static_maps_url_secret', $form_state->getValue('google_static_maps_url_secret')); diff --git a/modules/geolocation_google_maps/src/Form/GeolocationGoogleMapsSettings.php b/modules/geolocation_google_maps/src/Form/GeolocationGoogleMapsSettings.php index f9c172faf49178d85fa7069faec7d3b8626da2b0..64888b4349efdcb9d8a51130495b52c10672b37a 100644 --- a/modules/geolocation_google_maps/src/Form/GeolocationGoogleMapsSettings.php +++ b/modules/geolocation_google_maps/src/Form/GeolocationGoogleMapsSettings.php @@ -185,7 +185,7 @@ class GeolocationGoogleMapsSettings extends ConfigFormBase { * @param \Drupal\Core\Form\FormStateInterface $form_state * Form state. */ - public function addLibrariesSubmit(array &$form, FormStateInterface $form_state) { + public function addLibrariesSubmit(array &$form, FormStateInterface $form_state): void { $max = $form_state->get('fields_count') + 1; $form_state->set('fields_count', $max); $form_state->setRebuild(); @@ -225,7 +225,7 @@ class GeolocationGoogleMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $config = $this->configFactory()->getEditable('geolocation_google_maps.settings'); $config->set('google_map_api_key', $form_state->getValue('google_map_api_key')); $config->set('google_map_api_server_key', $form_state->getValue('google_map_api_server_key')); diff --git a/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/GoogleMapTypeStyle.php b/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/GoogleMapTypeStyle.php index 875fbf7c0fb79a9b76535d1d2b28e7f72be57abe..611e290ebbfb62f9d2df9dc6c1949d47ffc8fe64 100644 --- a/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/GoogleMapTypeStyle.php +++ b/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/GoogleMapTypeStyle.php @@ -80,13 +80,7 @@ class GoogleMapTypeStyle extends MapFeatureBase { $feature_settings['style'] = str_replace(["\n\r", "\n", "\r", " "], '', $feature_settings['style']); - try { - if (!json_decode($feature_settings['style'])) { - return $render_array; - } - } - catch (\Exception $e) { - \Drupal::messenger()->addMessage($this->t('Geolocation Style JSON failed: %error', ['%error' => $e])); + if (!json_decode($feature_settings['style'])) { return $render_array; } diff --git a/modules/geolocation_google_maps/tests/modules/geolocation_google_maps_test/geolocation_google_maps_test.install b/modules/geolocation_google_maps/tests/modules/geolocation_google_maps_test/geolocation_google_maps_test.install index cc3896aeaa34efc7a9d73156edb61ee26b81e7e8..b1a92ec8f908cb9d492524af99d871abc709c526 100644 --- a/modules/geolocation_google_maps/tests/modules/geolocation_google_maps_test/geolocation_google_maps_test.install +++ b/modules/geolocation_google_maps/tests/modules/geolocation_google_maps_test/geolocation_google_maps_test.install @@ -8,7 +8,7 @@ /** * Implements hook_install(). */ -function geolocation_google_maps_test_install() { +function geolocation_google_maps_test_install(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_google_maps.settings'); if (empty($config->get('google_map_api_key'))) { @@ -19,7 +19,7 @@ function geolocation_google_maps_test_install() { /** * Implements hook_uninstall(). */ -function geolocation_google_maps_test_uninstall() { +function geolocation_google_maps_test_uninstall(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_google_maps.settings'); if ($config->get('google_map_api_key') == 'AIzaSyBTq76GbylL-gnN9oHu4XV6se_N3h0YpWg') { diff --git a/modules/geolocation_google_maps/tests/src/Functional/GeolocationGoogleMapsGeocodingTest.php b/modules/geolocation_google_maps/tests/src/Functional/GeolocationGoogleMapsGeocodingTest.php index 57d69d1f4f91fa1fd12039926538606fcc18a799..f6a4d9dc2e61cfb3099d7e0440e7d06a422603f8 100644 --- a/modules/geolocation_google_maps/tests/src/Functional/GeolocationGoogleMapsGeocodingTest.php +++ b/modules/geolocation_google_maps/tests/src/Functional/GeolocationGoogleMapsGeocodingTest.php @@ -14,7 +14,7 @@ class GeolocationGoogleMapsGeocodingTest extends BrowserTestBase { /** * Modules to enable. * - * @var array + * @var string[] */ protected static $modules = [ 'geolocation', @@ -30,7 +30,7 @@ class GeolocationGoogleMapsGeocodingTest extends BrowserTestBase { /** * Test geocoding. */ - public function testGeocoder() { + public function testGeocoder(): void { /** @var \Drupal\geolocation\GeocoderInterface $geocoder */ $geocoder = \Drupal::service('plugin.manager.geolocation.geocoder')->getGeocoder('google_geocoding_api'); $location = $geocoder->geocode('H.Congreso de la Unión 66, El Parque, Venustiano Carranza, 15960 Ciudad de México, CDMX, Mexiko'); @@ -40,7 +40,7 @@ class GeolocationGoogleMapsGeocodingTest extends BrowserTestBase { /** * Test reverse geocoding. */ - public function testReverseGeocoder() { + public function testReverseGeocoder(): void { /** @var \Drupal\geolocation\GeocoderInterface $geocoder */ $geocoder = \Drupal::service('plugin.manager.geolocation.geocoder')->getGeocoder('google_geocoding_api'); $latitude = 38.56; diff --git a/modules/geolocation_here/geolocation_here.install b/modules/geolocation_here/geolocation_here.install index 1b30b459e5fecd8474e40cfce58f8c8d9ed41ef1..d95754a7e375341a78d9bfa8bc1803e462d195ba 100644 --- a/modules/geolocation_here/geolocation_here.install +++ b/modules/geolocation_here/geolocation_here.install @@ -12,7 +12,7 @@ use Drupal\Core\Url; * * Implements hook_requirements(). */ -function geolocation_here_requirements($phase) { +function geolocation_here_requirements(string $phase): array { $requirements = []; if ($phase == 'runtime') { $requirements['geolocation_here_api_key'] = [ @@ -38,6 +38,6 @@ function geolocation_here_requirements($phase) { /** * Implements hook_requirements(). */ -function geolocation_here_uninstall() { +function geolocation_here_uninstall(): void { Drupal::configFactory()->getEditable('here_maps.settings')->delete(); } diff --git a/modules/geolocation_here/src/Form/HereMapsSettings.php b/modules/geolocation_here/src/Form/HereMapsSettings.php index 8e7d398cdda8015e8778ff9f7f1b67b94a9a91de..67dd020ce1fc2ae987461b7639579100230ddff4 100644 --- a/modules/geolocation_here/src/Form/HereMapsSettings.php +++ b/modules/geolocation_here/src/Form/HereMapsSettings.php @@ -53,7 +53,7 @@ class HereMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $config = $this->configFactory()->getEditable('here_maps.settings'); $config->set('app_id', $form_state->getValue('app_id')); $config->set('app_code', $form_state->getValue('app_code')); diff --git a/modules/geolocation_leaflet/tests/src/Functional/LeafletCommonMapTest.php b/modules/geolocation_leaflet/tests/src/Functional/LeafletCommonMapTest.php index e63ba7467971e5b3d8e6b4b42795ae065a7d20fd..cb9b0678664864b4e9ec87cea44f66f97d1b64a2 100644 --- a/modules/geolocation_leaflet/tests/src/Functional/LeafletCommonMapTest.php +++ b/modules/geolocation_leaflet/tests/src/Functional/LeafletCommonMapTest.php @@ -33,7 +33,7 @@ class LeafletCommonMapTest extends BrowserTestBase { /** * Tests the boundary filter. */ - public function testCommonMap() { + public function testCommonMap(): void { $this->drupalGet('geolocation-demo/leaflet-commonmap'); $this->assertSession()->statusCodeEquals(200); } diff --git a/modules/geolocation_leaflet/tests/src/Functional/LeafletViewsSettingsTest.php b/modules/geolocation_leaflet/tests/src/Functional/LeafletViewsSettingsTest.php index cf40adb8cf04a3c69cb6e5ed47fa44d7da3f8d57..76067a3a17e2571b1282d1a0b8a6275e6794f0fd 100644 --- a/modules/geolocation_leaflet/tests/src/Functional/LeafletViewsSettingsTest.php +++ b/modules/geolocation_leaflet/tests/src/Functional/LeafletViewsSettingsTest.php @@ -36,7 +36,7 @@ class LeafletViewsSettingsTest extends BrowserTestBase { /** * Tests the Views admin UI and field handlers. */ - public function testViewsAdmin() { + public function testViewsAdmin(): void { $permissions = [ 'access administration pages', 'administer views', diff --git a/modules/geolocation_leaflet/tests/src/Kernel/NominatimTest.php b/modules/geolocation_leaflet/tests/src/Kernel/NominatimTest.php index 13a1c8c9ab6a24e673524a4900906d2b7a18fe4b..803c358007f24b69adb62591409c24030551b663 100644 --- a/modules/geolocation_leaflet/tests/src/Kernel/NominatimTest.php +++ b/modules/geolocation_leaflet/tests/src/Kernel/NominatimTest.php @@ -58,7 +58,7 @@ class NominatimTest extends KernelTestBase { /** * Test Geocoding. */ - public function testGeocoding() { + public function testGeocoding(): void { $nominatim = $this->geocoderManager->getGeocoder('nominatim'); $result = $nominatim->geocode('西宁站'); @@ -71,7 +71,7 @@ class NominatimTest extends KernelTestBase { /** * Test reverse Geocoding. */ - public function testReverseGeocoding() { + public function testReverseGeocoding(): void { $nominatim = $this->geocoderManager->getGeocoder('nominatim'); $result = $nominatim->reverseGeocode($this->latitudeXiningRailwayStation, $this->longitudeXiningRailwayStation); diff --git a/modules/geolocation_yandex/geolocation_yandex.install b/modules/geolocation_yandex/geolocation_yandex.install index 488f8f7e7c4cf612c6009caec05ea40db79f6e84..4ec56291479470e31067ac816590269ec942bfaa 100644 --- a/modules/geolocation_yandex/geolocation_yandex.install +++ b/modules/geolocation_yandex/geolocation_yandex.install @@ -8,11 +8,9 @@ use Drupal\Core\Url; /** - * {@inheritdoc} - * * Implements hook_requirements(). */ -function geolocation_yandex_requirements($phase) { +function geolocation_yandex_requirements(string $phase): array { $requirements = []; if ($phase == 'runtime') { $requirements['geolocation_yandex_api_key'] = [ @@ -35,26 +33,31 @@ function geolocation_yandex_requirements($phase) { /** * Move settings to new configuration. */ -function geolocation_yandex_update_8001(&$sandbox) { +function geolocation_yandex_update_8001(array &$sandbox): ?string { $config_factory = \Drupal::configFactory(); + /** @var ?\Drupal\Core\Config\Config $old_config */ $old_config = $config_factory->getEditable('yandex_maps.settings'); if (!$old_config) { - return; + return NULL; } $new_config = $config_factory->getEditable('geolocation_yandex.settings'); $new_config->set('api_key', $old_config->get('key')); $new_config->save(); $old_config->delete(); - return \Drupal::translation()->translate('Settings from old configuration moved to new one.'); + return (string) \Drupal::translation()->translate('Settings from old configuration moved to new one.'); } /** * Setting new config "packages" to "full". + * + * @phpstan-ignore-next-line */ -function geolocation_yandex_update_8002(&$sandbox) { +function geolocation_yandex_update_8002(array &$sandbox): ?string { $config_factory = \Drupal::configFactory(); $config = $config_factory->getEditable('geolocation_yandex.settings'); $config->set('packages', ['full']); $config->save(); + + return NULL; } diff --git a/modules/geolocation_yandex/src/Form/YandexMapsSettings.php b/modules/geolocation_yandex/src/Form/YandexMapsSettings.php index c56e963d4df073b0549b4605138a32e71c78ae30..8a1287e7e5ff58ad22a84f4160c609f4052d3163 100644 --- a/modules/geolocation_yandex/src/Form/YandexMapsSettings.php +++ b/modules/geolocation_yandex/src/Form/YandexMapsSettings.php @@ -16,7 +16,7 @@ class YandexMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { + public function buildForm(array $form, FormStateInterface $form_state): array { $config = $this->configFactory->get('geolocation_yandex.settings'); $form['api_key'] = [ @@ -41,14 +41,14 @@ class YandexMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function getFormId() { + public function getFormId(): string { return 'geolocation_yandex_settings'; } /** * {@inheritdoc} */ - protected function getEditableConfigNames() { + protected function getEditableConfigNames(): array { return [ 'geolocation_yandex.settings', ]; @@ -57,7 +57,7 @@ class YandexMapsSettings extends ConfigFormBase { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $config = $this->configFactory()->getEditable('geolocation_yandex.settings'); $config->set('api_key', $form_state->getValue('api_key')); $config->set('packages', array_filter(array_values($form_state->getValue('packages')))); diff --git a/modules/geolocation_yandex/tests/modules/geolocation_yandex_test/geolocation_yandex_test.install b/modules/geolocation_yandex/tests/modules/geolocation_yandex_test/geolocation_yandex_test.install index 917a608c22cc1365ba7fa4a6e7a9f0b3cd300988..911b73c8c9fb832c7779d6f6aeb51553749532d8 100644 --- a/modules/geolocation_yandex/tests/modules/geolocation_yandex_test/geolocation_yandex_test.install +++ b/modules/geolocation_yandex/tests/modules/geolocation_yandex_test/geolocation_yandex_test.install @@ -8,7 +8,7 @@ /** * Implements hook_install(). */ -function geolocation_yandex_test_install() { +function geolocation_yandex_test_install(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_yandex.settings'); if (empty($config->get('api_key'))) { @@ -19,7 +19,7 @@ function geolocation_yandex_test_install() { /** * Implements hook_uninstall(). */ -function geolocation_yandex_test_uninstall() { +function geolocation_yandex_test_uninstall(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_yandex.settings'); if ($config->get('api_key') == '060d60d6-6907-44a6-99cb-ca9c56796211') { diff --git a/modules/geolocation_yandex/tests/src/Functional/YandexGeocodingTest.php b/modules/geolocation_yandex/tests/src/Functional/YandexGeocodingTest.php index 1dd19bcc4e06d421878ee994253e5125e92087a9..3f3283381a6eadf10cfea9b5955fa8120cd01ddc 100644 --- a/modules/geolocation_yandex/tests/src/Functional/YandexGeocodingTest.php +++ b/modules/geolocation_yandex/tests/src/Functional/YandexGeocodingTest.php @@ -14,7 +14,7 @@ class YandexGeocodingTest extends BrowserTestBase { /** * Modules to enable. * - * @var array + * @var string[] */ protected static $modules = [ 'geolocation', @@ -44,7 +44,7 @@ class YandexGeocodingTest extends BrowserTestBase { /** * Test geocoding. */ - public function testGeocoder() { + public function testGeocoder(): void { /** @var \Drupal\geolocation\GeocoderInterface $geocoder */ $geocoder = \Drupal::service('plugin.manager.geolocation.geocoder')->getGeocoder('yandex'); $location = $geocoder->geocode('Бишкек, Кыргызстан'); @@ -57,7 +57,7 @@ class YandexGeocodingTest extends BrowserTestBase { /** * Test reverse geocoding. */ - public function testReverseGeocoder() { + public function testReverseGeocoder(): void { /** @var \Drupal\geolocation\GeocoderInterface $geocoder */ $geocoder = \Drupal::service('plugin.manager.geolocation.geocoder')->getGeocoder('yandex'); $address = $geocoder->reverseGeocode($this->bishkekFlooredLatitude, $this->bishkekFlooredLongitude); diff --git a/phpstan.neon b/phpstan.neon index cabe99cd7ec153f9bc2ecf1a86d79ef1f83165e5..a441f6a346d78e350cfbb0b5b29f9914c4ec9db6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,16 +2,33 @@ parameters: level: 6 excludePaths: - # Optional dependencies. + # Geocoder dependency not resolved during test. + - */src/Plugin/Geocoder/* + # Migrate dependency not resolved during test. - */src/Plugin/migrate/* + # Feeds dependency not resolved during test. - */src/Plugin/Tamper/* - - */src/Plugin/Geocoder/* - */src/Feeds/* + - modules\geolocation_geometry\modules\geolocation_geometry_data\geolocation_geometry_data.install # Hook implementations are weird. - *.module + - *.tokens.inc + # Address dependency not resolved during test. + - modules/geolocation_address/* + # SearchAPI dependency not resolved during test. + - modules/geolocation_search_api/* + # Geocodio dependency not resolved during test. + - modules/geolocation_geocodio/* + # Geofield dependency not resolved during test. + - modules/geolocation_geofield/* + # GPX dependency not resolved during test. + - modules/geolocation_gpx/* ignoreErrors: # best practice in Drupal, so we cannot fix that. - '#Unsafe usage of new static\(\)#' - '#\\Drupal calls should be avoided in classes, use dependency injection instead#' - '#no value type specified in iterable type#' + - "#with generic interface Drupal\\\\Core\\\\Field\\\\FieldItemListInterface but does not specify its types#" + - "#Call to an undefined method Drupal\\\\Tests\\\\WebAssert::waitForElement#" + - "#Call to an undefined method Drupal\\\\Tests\\\\WebAssert::assertWaitOnAjaxRequest#" diff --git a/src/DataLayerProviderBase.php b/src/DataLayerProviderBase.php index 9b49f226fd96b40c9ce7a21d9c4267929882e21f..f968f5f92a58d5005874ad1fee71d0f9a3ce9ea2 100644 --- a/src/DataLayerProviderBase.php +++ b/src/DataLayerProviderBase.php @@ -131,7 +131,7 @@ abstract class DataLayerProviderBase extends PluginBase implements DataLayerProv ] ); - $render_array['#layers'][$layer_id] = $this->getLayerRenderData($data_layer_option_id, $layer_info['settings'] ?? []); + $render_array['#layers'][$layer_id] = $this->getLayerRenderData($data_layer_option_id, $settings); if (!empty($settings['features'])) { uasort($settings['features'], [SortArray::class, 'sortByWeightElement']); diff --git a/src/DataLayerProviderManager.php b/src/DataLayerProviderManager.php index 99edcf3c89366b4ad84d022f4f8babde0215dac9..987e252a19ad9fc737a04cc5e5048267b4f5fcc8 100644 --- a/src/DataLayerProviderManager.php +++ b/src/DataLayerProviderManager.php @@ -55,17 +55,11 @@ class DataLayerProviderManager extends DefaultPluginManager { public function getDataLayerProviderDefinitions(): array { $dataLayers = []; $definitions = $this->getDefinitions(); - try { - foreach ($definitions as $dataLayerProviderId => $dataLayerProviderDefinition) { - $dataLayers[$dataLayerProviderId] = $dataLayerProviderDefinition; - } - - return $dataLayers; - } - catch (\Exception $e) { - $this->getLogger('geolocation')->warning($e->getMessage()); - return []; + foreach ($definitions as $dataLayerProviderId => $dataLayerProviderDefinition) { + $dataLayers[$dataLayerProviderId] = $dataLayerProviderDefinition; } + + return $dataLayers; } /** diff --git a/src/DataProviderBase.php b/src/DataProviderBase.php index f82fdc9e432a23e3a14913615154b649f4c0b24a..fc9446bee063cc7f4724cc7851f85ade2314d995 100644 --- a/src/DataProviderBase.php +++ b/src/DataProviderBase.php @@ -260,6 +260,8 @@ abstract class DataProviderBase extends PluginBase implements DataProviderInterf * * @return \Drupal\Core\Field\FieldItemList|null * Field items. + * + * @phpstan-ignore-next-line */ protected function getFieldItemsFromViewsRow(ResultRow $row, FieldPluginBase $viewsField = NULL): ?FieldItemList { if (!$viewsField) { diff --git a/src/Element/GeolocationMapGeometry.php b/src/Element/GeolocationMapGeometry.php index 5e6a4dd31424e5b886c73d9db60bf7d06702b065..f0fa39a44c6672de83909462f9b56a0d0734dbf8 100644 --- a/src/Element/GeolocationMapGeometry.php +++ b/src/Element/GeolocationMapGeometry.php @@ -72,10 +72,10 @@ class GeolocationMapGeometry extends RenderElement { $render_array['#attributes']->setAttribute('id', $render_array['#id'] ?? uniqid('geometry-')); $render_array['#attributes']->setAttribute('data-stroke-color', $render_array['#stroke_color'] ?? '#0000FF'); - $render_array['#attributes']->setAttribute('data-stroke-width', (int) $render_array['#stroke_width'] ?? 2); - $render_array['#attributes']->setAttribute('data-stroke-opacity', (float) $render_array['#stroke_opacity'] ?? 1); + $render_array['#attributes']->setAttribute('data-stroke-width', $render_array['#stroke_width'] ?? 2); + $render_array['#attributes']->setAttribute('data-stroke-opacity', $render_array['#stroke_opacity'] ?? 1); $render_array['#attributes']->setAttribute('data-fill-color', $render_array['#fill_color'] ?? $render_array['#stroke_color'] ?? '#0000FF'); - $render_array['#attributes']->setAttribute('data-fill-opacity', (float) $render_array['#fill_opacity'] ?? 0.2); + $render_array['#attributes']->setAttribute('data-fill-opacity', $render_array['#fill_opacity'] ?? 0.2); foreach (Element::children($render_array) as $child) { $render_array['#children'][] = $render_array[$child]; diff --git a/src/EventSubscriber/AjaxResponseSubscriber.php b/src/EventSubscriber/AjaxResponseSubscriber.php index 1b1ecb0ac1755d11a9882a635b83e87cf5f15e74..394f43366301f373dfbaa8235f2e202aefbb7174 100644 --- a/src/EventSubscriber/AjaxResponseSubscriber.php +++ b/src/EventSubscriber/AjaxResponseSubscriber.php @@ -19,7 +19,7 @@ class AjaxResponseSubscriber implements EventSubscriberInterface { * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * The response event, which contains the possible AjaxResponse object. */ - public function onResponse(ResponseEvent $event) { + public function onResponse(ResponseEvent $event): void { $response = $event->getResponse(); // Only alter views ajax responses. diff --git a/src/GeolocationItemListInterface.php b/src/GeolocationItemListInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..981e69a34830ffccc62fd352a29daab73701a52b --- /dev/null +++ b/src/GeolocationItemListInterface.php @@ -0,0 +1,25 @@ +<?php + +namespace Drupal\geolocation; + +use Drupal\Core\Field\FieldItemListInterface; + +/** + * {@inheritdoc} + * + * @extends FieldItemListInterface<\Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem> + * + * @property ?float $lat + * Latitude. + * @property ?float $lng + * Longitude. + * @property ?float $lat_sin + * Latitude Sine. + * @property ?float $lat_cos + * Latitude Cosine. + * @property ?float $lng_rad + * Longitude Radian. + * @property ?mixed $data + * Data. + */ +interface GeolocationItemListInterface extends FieldItemListInterface {} diff --git a/src/KeyProvider.php b/src/KeyProvider.php index c3ee3eed666212cbabd36b4da9984be821f232c4..dc2f01f071ea2cbc90cf084f63b515aa13f75fc0 100644 --- a/src/KeyProvider.php +++ b/src/KeyProvider.php @@ -14,7 +14,7 @@ class KeyProvider { * * So that we don't need to store plain text api key secrets in config file. */ - public static function getKeyValue($api_key) { + public static function getKeyValue(string $api_key): string { if (empty($api_key)) { return $api_key; } diff --git a/src/LayerFeatureBase.php b/src/LayerFeatureBase.php index 4e04e6f22c72dc19016972726c98dfe19651fc2f..736680b1bffee3dd04c96abb10c55adb6950d35e 100644 --- a/src/LayerFeatureBase.php +++ b/src/LayerFeatureBase.php @@ -101,7 +101,7 @@ abstract class LayerFeatureBase extends PluginBase implements LayerFeatureInterf /** * {@inheritdoc} */ - public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []) {} + public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []): void {} /** * Get JS Module path. @@ -110,7 +110,7 @@ abstract class LayerFeatureBase extends PluginBase implements LayerFeatureInterf * JS file path to load. */ private function getJavascriptModulePath() : ?string { - $class_name = (new \ReflectionClass($this))->getShortName() ?? ''; + $class_name = (new \ReflectionClass($this))->getShortName(); $module_path = $this->moduleHandler->getModule($this->getPluginDefinition()['provider'])->getPath(); @@ -150,7 +150,7 @@ abstract class LayerFeatureBase extends PluginBase implements LayerFeatureInterf ]); if (\Drupal::service('library.discovery')->getLibraryByName($this->getPluginDefinition()['provider'], 'layerfeature.' . $this->getPluginId())) { - $render_array['#attached'] = BubbleableMetadata::mergeAttachments($render_array['#attached'] ?? [], [ + $render_array['#attached'] = BubbleableMetadata::mergeAttachments($render_array['#attached'], [ 'library' => [ $this->getPluginDefinition()['provider'] . '/layerfeature.' . $this->getPluginId(), ], diff --git a/src/LayerFeatureInterface.php b/src/LayerFeatureInterface.php index 2d6fb7b054a8c1ba6e29123930b131f6e6122f44..747af404e3d24da04de1ebd55bf62001594b00b5 100644 --- a/src/LayerFeatureInterface.php +++ b/src/LayerFeatureInterface.php @@ -69,7 +69,7 @@ interface LayerFeatureInterface extends PluginInspectionInterface { * @param array $parents * Element parents. */ - public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []); + public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []): void; /** * Alter render array. diff --git a/src/LocationBase.php b/src/LocationBase.php index 3558b3308b468f3132ab2d993787cfb95b0d6ce4..a533812bc41f5d4f244bfe1ab7ecebbd8a7b1fc5 100644 --- a/src/LocationBase.php +++ b/src/LocationBase.php @@ -55,7 +55,7 @@ abstract class LocationBase extends PluginBase implements LocationInterface, Con * @param \Drupal\Core\Form\FormStateInterface $form_state * Form State. */ - public function validateSettingsForm(array $values, FormStateInterface $form_state) {} + public function validateSettingsForm(array $values, FormStateInterface $form_state): void {} /** * {@inheritdoc} diff --git a/src/LocationInputBase.php b/src/LocationInputBase.php index e8f8048ad6bf8e22e8066b49d1d3d97835b0c677..565672439980887629052b7edbda69a85993cf5c 100644 --- a/src/LocationInputBase.php +++ b/src/LocationInputBase.php @@ -68,7 +68,7 @@ abstract class LocationInputBase extends PluginBase implements LocationInputInte /** * {@inheritdoc} */ - public function validateSettingsForm(array $values, FormStateInterface $form_state) {} + public function validateSettingsForm(array $values, FormStateInterface $form_state): void {} /** * {@inheritdoc} @@ -109,7 +109,7 @@ abstract class LocationInputBase extends PluginBase implements LocationInputInte $path = $this->getJavascriptModulePath(); if ($path) { - $form = BubbleableMetadata::mergeAttachments($form ?? [], [ + $form = BubbleableMetadata::mergeAttachments($form, [ '#attached' => [ 'drupalSettings' => [ 'geolocation' => [ diff --git a/src/LocationInputManager.php b/src/LocationInputManager.php index 7cadb0f7a3a0c3d378c769588d6312db8d077e68..8465c3e9686ac92adf0e9d996bf06ac2034d31c3 100644 --- a/src/LocationInputManager.php +++ b/src/LocationInputManager.php @@ -78,7 +78,7 @@ class LocationInputManager extends DefaultPluginManager { $form = [ '#type' => 'table', '#caption' => $this->t('<b><Location input/b>'), - '#prefix' => $title ?? $this->t('Each option will, if it can be applied, supersede any following option.'), + '#prefix' => $title ?: $this->t('Each option will, if it can be applied, supersede any following option.'), '#header' => [ [ 'data' => $this->t('Enable'), @@ -254,7 +254,7 @@ class LocationInputManager extends DefaultPluginManager { $form['coordinates'] = [ '#type' => 'geolocation_input', - '#title' => $title ?? $this->t('Coordinates'), + '#title' => $title ?: $this->t('Coordinates'), '#attributes' => [ 'class' => [ 'geolocation-location-input-coordinates', diff --git a/src/MapFeatureBase.php b/src/MapFeatureBase.php index ed69dea9da33395d25d89b0d1335fdab7623d655..97004ae3acfff6e222062b787ad3b0035ea0fdf8 100644 --- a/src/MapFeatureBase.php +++ b/src/MapFeatureBase.php @@ -109,7 +109,7 @@ abstract class MapFeatureBase extends PluginBase implements MapFeatureInterface, /** * {@inheritdoc} */ - public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []) {} + public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []): void {} /** * Get the path to load JS module. @@ -118,7 +118,7 @@ abstract class MapFeatureBase extends PluginBase implements MapFeatureInterface, * JS Module path. */ private function getJavascriptModulePath() : ?string { - $class_name = (new \ReflectionClass($this))->getShortName() ?? ''; + $class_name = (new \ReflectionClass($this))->getShortName(); $module_path = $this->moduleHandler->getModule($this->getPluginDefinition()['provider'])->getPath(); @@ -153,7 +153,7 @@ abstract class MapFeatureBase extends PluginBase implements MapFeatureInterface, ]); if (\Drupal::service('library.discovery')->getLibraryByName($this->getPluginDefinition()['provider'], 'mapfeature.' . $this->getPluginId())) { - $render_array['#attached'] = BubbleableMetadata::mergeAttachments($render_array['#attached'] ?? [], [ + $render_array['#attached'] = BubbleableMetadata::mergeAttachments($render_array['#attached'], [ 'library' => [ $this->getPluginDefinition()['provider'] . '/mapfeature.' . $this->getPluginId(), ], diff --git a/src/MapFeatureInterface.php b/src/MapFeatureInterface.php index 2d4d73c9e258fcea466a5d899270716ddc1ff7bc..5cb9b713c26f76475383d4a6e5b471c55972f92a 100644 --- a/src/MapFeatureInterface.php +++ b/src/MapFeatureInterface.php @@ -69,7 +69,7 @@ interface MapFeatureInterface extends PluginInspectionInterface { * @param array $parents * Element parents. */ - public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []); + public function validateSettingsForm(array $values, FormStateInterface $form_state, array $parents = []): void; /** * Alter render array. diff --git a/src/MapFeatureManager.php b/src/MapFeatureManager.php index 2eeba295324efb3261e8bd194485dd7af8802b82..c5641e1f00414964b5e8108f7f32600eccc9d738 100644 --- a/src/MapFeatureManager.php +++ b/src/MapFeatureManager.php @@ -228,7 +228,7 @@ class MapFeatureManager extends DefaultPluginManager { * @param \Drupal\Core\Form\FormStateInterface $form_state * Form state. */ - public function validateMapFeatureForms(array $element, FormStateInterface $form_state) { + public function validateMapFeatureForms(array $element, FormStateInterface $form_state): void { $values = $form_state->getValues(); $parents = []; diff --git a/src/Plugin/Block/GeolocationBlock.php b/src/Plugin/Block/GeolocationBlock.php index 15f9bc61cc6399e9289ab45a852e561808597862..03d02d9379165d9c97c6d49e7d412005fb9f0270 100644 --- a/src/Plugin/Block/GeolocationBlock.php +++ b/src/Plugin/Block/GeolocationBlock.php @@ -221,7 +221,7 @@ class GeolocationBlock extends BlockBase implements ContainerFactoryPluginInterf * @param \Drupal\Core\Form\FormStateInterface $form_state * Current form state. */ - public function addCallback(array &$form, FormStateInterface $form_state) { + public function addCallback(array &$form, FormStateInterface $form_state): void { $locations = $form_state->get('locations'); $locations[] = [ 'marker_title' => '', @@ -243,7 +243,7 @@ class GeolocationBlock extends BlockBase implements ContainerFactoryPluginInterf * @param \Drupal\Core\Form\FormStateInterface $form_state * Current form state. */ - public function removeCallback(array &$form, FormStateInterface $form_state) { + public function removeCallback(array &$form, FormStateInterface $form_state): void { $parents = $form_state->getTriggeringElement()['#parents']; end($parents); $key = prev($parents); @@ -271,7 +271,7 @@ class GeolocationBlock extends BlockBase implements ContainerFactoryPluginInterf /** * {@inheritdoc} */ - public function blockSubmit($form, FormStateInterface $form_state) { + public function blockSubmit($form, FormStateInterface $form_state): void { $this->configuration['map_provider_id'] = $form_state->getValue('map_provider_id'); $this->configuration['map_provider_settings'] = $form_state->getValue('map_provider_settings'); $this->configuration['centre'] = $form_state->getValue('centre'); diff --git a/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php b/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php index 65b5f66a8a51822b37a717776160a94dba674cf3..9396820070c0276ef666a033d606899ceea0cfe5 100644 --- a/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php +++ b/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php @@ -29,7 +29,7 @@ class GeolocationTokenFormatter extends FormatterBase { /** * Data provider. * - * @var \Drupal\geolocation\DataProviderInterface|null + * @var \Drupal\geolocation\DataProviderInterface */ protected DataProviderInterface $dataProvider; diff --git a/src/Plugin/Field/FieldType/GeolocationItem.php b/src/Plugin/Field/FieldType/GeolocationItem.php index fb0f61d0ea726054ce48702d41bc79d50e093c46..774befe1915ae422ae50c1a06bfd14571cc273be 100644 --- a/src/Plugin/Field/FieldType/GeolocationItem.php +++ b/src/Plugin/Field/FieldType/GeolocationItem.php @@ -19,6 +19,19 @@ use Drupal\geolocation\TypedData\GeolocationComputed; * default_widget = "geolocation_latlng", * default_formatter = "geolocation_latlng" * ) + * + * @property ?float $lat + * Latitude. + * @property ?float $lng + * Longitude. + * @property ?float $lat_sin + * Latitude Sine. + * @property ?float $lat_cos + * Latitude Cosine. + * @property ?float $lng_rad + * Longitude Radian. + * @property ?mixed $data + * Data. */ class GeolocationItem extends FieldItemBase { @@ -170,6 +183,11 @@ class GeolocationItem extends FieldItemBase { /** * {@inheritdoc} + * + * @param string $property_name + * Property Name. + * @param bool $notify + * Notify. */ public function onChange($property_name, $notify = TRUE): void { parent::onChange($property_name, $notify); diff --git a/src/Plugin/geolocation/LayerFeature/GeolocationMarkerScrollToId.php b/src/Plugin/geolocation/LayerFeature/GeolocationMarkerScrollToId.php index 157796e02fec6fc0c77f89c7de671269f9a8049e..6b7045159286a7d3360f84291edf69a556a10876 100644 --- a/src/Plugin/geolocation/LayerFeature/GeolocationMarkerScrollToId.php +++ b/src/Plugin/geolocation/LayerFeature/GeolocationMarkerScrollToId.php @@ -3,7 +3,7 @@ namespace Drupal\geolocation\Plugin\geolocation\MapFeature; use Drupal\Core\Template\Attribute; -use Drupal\geolocation\MapFeatureBase; +use Drupal\geolocation\LayerFeatureBase; use Drupal\geolocation\MapProviderInterface; /** @@ -16,7 +16,7 @@ use Drupal\geolocation\MapProviderInterface; * type = "all", * ) */ -class GeolocationMarkerScrollToId extends MapFeatureBase { +class GeolocationMarkerScrollToId extends LayerFeatureBase { /** * {@inheritdoc} @@ -46,7 +46,9 @@ class GeolocationMarkerScrollToId extends MapFeatureBase { /** * {@inheritdoc} */ - public function alterMap(array $render_array, array $feature_settings = [], array $context = [], MapProviderInterface $mapProvider = NULL): array { + public function alterLayer(array $render_array, string $layer_id, array $feature_settings = [], array $context = []): array { + $render_array = parent::alterLayer($render_array, $layer_id, $feature_settings, $context); + if (empty($render_array['#children']['locations'])) { return $render_array; } @@ -77,7 +79,7 @@ class GeolocationMarkerScrollToId extends MapFeatureBase { } } - return parent::alterMap($render_array, $feature_settings, $context, $mapProvider); + return $render_array; } } diff --git a/src/Plugin/geolocation/LayerFeature/MarkerZoomByAnchor.php b/src/Plugin/geolocation/LayerFeature/MarkerZoomByAnchor.php index 79f3b69bd8cb23d543597e38941f1ecbe96e42a8..e6fa12c546c8e7b498004070f5887fda3a4e9337 100644 --- a/src/Plugin/geolocation/LayerFeature/MarkerZoomByAnchor.php +++ b/src/Plugin/geolocation/LayerFeature/MarkerZoomByAnchor.php @@ -47,6 +47,8 @@ class MarkerZoomByAnchor extends LayerFeatureBase { * {@inheritdoc} */ public function alterLayer(array $render_array, string $layer_id, array $feature_settings = [], array $context = []): array { + $render_array = parent::alterLayer($render_array, $layer_id, $feature_settings, $context); + if (empty($render_array['#children']['locations'])) { return $render_array; } @@ -77,7 +79,7 @@ class MarkerZoomByAnchor extends LayerFeatureBase { } } - return parent::alterLayer($render_array, $feature_settings, $context); + return $render_array; } } diff --git a/src/Plugin/geolocation/Location/FirstRow.php b/src/Plugin/geolocation/Location/FirstRow.php index 57bfd8ef97fabd656ce1d647c77bfbd9b5a44082..66b0e60a3a90efaff74694942f0aabde70a9718b 100644 --- a/src/Plugin/geolocation/Location/FirstRow.php +++ b/src/Plugin/geolocation/Location/FirstRow.php @@ -85,7 +85,6 @@ class FirstRow extends LocationBase implements LocationInterface { return parent::getCoordinates($location_option_id, $location_option_settings, $context); } - /** @var \Drupal\geolocation\DataProviderInterface $data_provider */ $data_provider = $this->dataProviderManager->getDataProviderByViewsField($source_field); if (empty($data_provider)) { diff --git a/src/Plugin/geolocation/Location/ViewsBoundaryFilter.php b/src/Plugin/geolocation/Location/ViewsBoundaryFilter.php index 8224ba6480b44bae7c713dc0d71ed03b9c941047..cb5f49b7df2736b518b8e6505fe67ca4e14c1ee7 100644 --- a/src/Plugin/geolocation/Location/ViewsBoundaryFilter.php +++ b/src/Plugin/geolocation/Location/ViewsBoundaryFilter.php @@ -29,6 +29,7 @@ class ViewsBoundaryFilter extends LocationBase implements LocationInterface { /** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */ foreach ($displayHandler->getHandlers('filter') as $delta => $filter) { if ( + // @phpstan-ignore-next-line $filter->getPluginId() === 'geolocation_filter_boundary' && $filter !== $context['views_filter'] ?? NULL ) { diff --git a/src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php b/src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php index 6366822f19451aaacca919666f6139fff0dd7d61..c5fcac7ff47276c91748254b9af44ef4128bca15 100644 --- a/src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php +++ b/src/Plugin/geolocation/MapCenter/ViewsBoundaryFilter.php @@ -76,7 +76,7 @@ class ViewsBoundaryFilter extends MapCenterBase implements MapCenterInterface { return $render_array; } - /** @var \Drupal\geolocation\Plugin\views\filter\BoundaryFilter $handler */ + /** @var \Drupal\geolocation\Plugin\views\filter\BoundaryFilter|null $handler */ $handler = $displayHandler->getHandler('filter', substr($center_option_id, 16)); if (!$handler) { diff --git a/src/Plugin/views/argument/BoundaryArgument.php b/src/Plugin/views/argument/BoundaryArgument.php index dacd46e34c5658ba49492b8738201fd74df81517..77a84c4eb889e3347779d73339a69d84e80e48c8 100644 --- a/src/Plugin/views/argument/BoundaryArgument.php +++ b/src/Plugin/views/argument/BoundaryArgument.php @@ -23,6 +23,11 @@ class BoundaryArgument extends ArgumentPluginBase { /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); @@ -31,6 +36,9 @@ class BoundaryArgument extends ArgumentPluginBase { /** * {@inheritdoc} + * + * @param int|string|false $group_by + * Group by. */ public function query($group_by = FALSE): void { if (!($this->query instanceof Sql)) { diff --git a/src/Plugin/views/argument/EntityArgument.php b/src/Plugin/views/argument/EntityArgument.php index fa06b3f6d69e6010ff8f5bc418c778fb04e524fa..b873a636f985f7aae588fb99c568380086f537f3 100644 --- a/src/Plugin/views/argument/EntityArgument.php +++ b/src/Plugin/views/argument/EntityArgument.php @@ -67,6 +67,11 @@ class EntityArgument extends ProximityArgument implements ContainerFactoryPlugin /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); diff --git a/src/Plugin/views/argument/GeocoderArgument.php b/src/Plugin/views/argument/GeocoderArgument.php index 118e5ed9a3e91d58b5ebef0c92b9aa12db9d5521..1e20b0707639d4816db9acd83fe9d6dd3f20f2e1 100644 --- a/src/Plugin/views/argument/GeocoderArgument.php +++ b/src/Plugin/views/argument/GeocoderArgument.php @@ -55,6 +55,11 @@ class GeocoderArgument extends ProximityArgument implements ContainerFactoryPlug /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); diff --git a/src/Plugin/views/argument/ProximityArgument.php b/src/Plugin/views/argument/ProximityArgument.php index c0e757309982b0391987e256f2efdcd4eaeb8bf9..c799341153fe2fddc75540810b742b7da64e5b64 100644 --- a/src/Plugin/views/argument/ProximityArgument.php +++ b/src/Plugin/views/argument/ProximityArgument.php @@ -29,8 +29,13 @@ class ProximityArgument extends Formula { /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { + public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); $form['description']['#markup'] .= $this->t('<br/> Proximity format should be in the following format: <strong>"37.7749295,-122.41941550000001<=5mi"</strong> (defaults to km).'); } @@ -38,7 +43,7 @@ class ProximityArgument extends Formula { /** * Get the formula for this argument. */ - public function getFormula() { + public function getFormula(): ?string { // Parse argument for reference location. $values = $this->getParsedReferenceLocation(); // Make sure we have enough information to start with. @@ -56,17 +61,19 @@ class ProximityArgument extends Formula { $this->operator = $values['operator'] ?? '<'; $this->distance = $distance; - return !empty($formula) ? str_replace('***table***', $this->tableAlias, $formula) : FALSE; - } - else { - return FALSE; + return !empty($formula) ? str_replace('***table***', $this->tableAlias, $formula) : NULL; } + + return NULL; } /** * {@inheritdoc} + * + * @param int|string|false $group_by + * Group by. */ - public function query($group_by = FALSE) { + public function query($group_by = FALSE): void { $this->ensureMyTable(); // Now that our table is secure, get our formula. $placeholder = $this->placeholder(); diff --git a/src/Plugin/views/display/Layer.php b/src/Plugin/views/display/Layer.php index d567c5295a747ab8846fe6b6965c1cd870e1f7dd..ff0c22a84a95342a364770ea384d50bd36d32bd8 100644 --- a/src/Plugin/views/display/Layer.php +++ b/src/Plugin/views/display/Layer.php @@ -44,7 +44,7 @@ class Layer extends Attachment { /** * {@inheritdoc} */ - protected function defineOptions() { + protected function defineOptions(): array { $options = parent::defineOptions(); // Force the style plugin to 'entity_reference_style' and the row plugin to @@ -62,8 +62,13 @@ class Layer extends Attachment { /** * {@inheritdoc} + * + * @param array $categories + * Categories. + * @param array $options + * Options. */ - public function optionsSummary(&$categories, &$options) { + public function optionsSummary(&$categories, &$options): void { parent::optionsSummary($categories, $options); unset($options['attachment_position']); @@ -72,8 +77,13 @@ class Layer extends Attachment { /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { + public function buildOptionsForm(&$form, FormStateInterface $form_state): void { // It is very important to call the parent function here: parent::buildOptionsForm($form, $form_state); switch ($form_state->get('section')) { @@ -101,14 +111,21 @@ class Layer extends Attachment { /** * {@inheritdoc} */ - public function getType() { + public function getType(): string { return 'geolocation_layer'; } /** * {@inheritdoc} + * + * @param \Drupal\views\ViewExecutable $view + * View. + * @param string $display_id + * Display ID. + * @param array $build + * Build render array. */ - public function attachTo(ViewExecutable $view, $display_id, array &$build) { + public function attachTo(ViewExecutable $view, $display_id, array &$build): void { $displays = $this->getOption('displays'); if (empty($displays[$display_id])) { @@ -128,6 +145,7 @@ class Layer extends Attachment { } if (empty($this->view->geolocationLayers)) { + // @phpstan-ignore-next-line $this->view->geolocationLayers = []; } @@ -140,7 +158,7 @@ class Layer extends Attachment { /** * {@inheritdoc} */ - public function buildRenderable(array $args = [], $cache = TRUE) { + public function buildRenderable(array $args = [], $cache = TRUE): array { $render = parent::buildRenderable($args, $cache); $render['#embed'] = TRUE; diff --git a/src/Plugin/views/field/GeolocationField.php b/src/Plugin/views/field/GeolocationField.php index 2ad3b7f482e6524a92d2c79e9febc0a5e74d1880..70b7b8639d0f0a0b05a551b22bdfe885c7762d88 100644 --- a/src/Plugin/views/field/GeolocationField.php +++ b/src/Plugin/views/field/GeolocationField.php @@ -7,7 +7,7 @@ use Drupal\geolocation\Plugin\Field\FieldType\GeolocationItem; use Drupal\views\Plugin\views\field\EntityField; /** - * Field handler for geolocaiton field. + * Field handler for geolocation field. * * @ingroup views_field_handlers * @@ -17,8 +17,13 @@ class GeolocationField extends EntityField { /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { + public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); // Remove the click sort field selector. @@ -27,8 +32,11 @@ class GeolocationField extends EntityField { /** * {@inheritdoc} + * + * @param array $tokens + * Tokens. */ - protected function documentSelfTokens(&$tokens) { + protected function documentSelfTokens(&$tokens): void { parent::documentSelfTokens($tokens); $tokens['{{ ' . $this->options['id'] . '__lat_sex }}'] = $this->t('Latitude in sexagesimal notation.'); $tokens['{{ ' . $this->options['id'] . '__lng_sex }}'] = $this->t('Longitude in sexagesimal notation.'); @@ -36,8 +44,13 @@ class GeolocationField extends EntityField { /** * {@inheritdoc} + * + * @param array $tokens + * Tokens. + * @param array $item + * Item. */ - protected function addSelfTokens(&$tokens, $item) { + protected function addSelfTokens(&$tokens, $item): void { parent::addSelfTokens($tokens, $item); if (empty($item['raw'])) { return; diff --git a/src/Plugin/views/field/ProximityField.php b/src/Plugin/views/field/ProximityField.php index 0e0ff9eddfc360cecb3b7a20b7d68251f4480f1a..e2beb52b8893d8984a58830a551bf7400ba40246 100644 --- a/src/Plugin/views/field/ProximityField.php +++ b/src/Plugin/views/field/ProximityField.php @@ -59,8 +59,13 @@ class ProximityField extends NumericField implements ContainerFactoryPluginInter /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { + public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); $form['center'] = $this->locationManager->getLocationOptionsForm($this->options['center'], ['views_field' => $this]); @@ -93,7 +98,7 @@ class ProximityField extends NumericField implements ContainerFactoryPluginInter /** * {@inheritdoc} */ - public function query() { + public function query(): void { /** @var \Drupal\views\Plugin\views\query\Sql $query */ $query = $this->query; @@ -114,7 +119,7 @@ class ProximityField extends NumericField implements ContainerFactoryPluginInter /** * {@inheritdoc} */ - public function getValue(ResultRow $values, $field = NULL) { + public function getValue(ResultRow $values, $field = NULL): int|null|float { $value = parent::getValue($values, $field); // NULL means no proximity calculated, 0 means 0m distance. diff --git a/src/Plugin/views/field/ProximityFormField.php b/src/Plugin/views/field/ProximityFormField.php index 5be032d83649a81b6a65c9a50eedc96b2f7ad2ff..aab9a6149966887c7cdf83b7660b5b6e211043f8 100644 --- a/src/Plugin/views/field/ProximityFormField.php +++ b/src/Plugin/views/field/ProximityFormField.php @@ -57,8 +57,13 @@ class ProximityFormField extends ProximityField implements ContainerFactoryPlugi /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { + public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); $user_input = $form_state->getUserInput(); @@ -76,9 +81,14 @@ class ProximityFormField extends ProximityField implements ContainerFactoryPlugi } /** - * Provide a more useful title to improve the accessibility. + * Views form. + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ - public function viewsForm(&$form, FormStateInterface $form_state) { + public function viewsForm(array &$form, FormStateInterface $form_state): void { $form['#tree'] = TRUE; $form['center'] = $this->locationInputManager->getForm($this->options['center'], ['views_field' => $this], $this->getCenter()); @@ -108,7 +118,7 @@ class ProximityFormField extends ProximityField implements ContainerFactoryPlugi * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * Thrown when the user tried to access an action without access to it. */ - public function viewsFormSubmit(array &$form, FormStateInterface $form_state) { + public function viewsFormSubmit(array &$form, FormStateInterface $form_state): void { if ($form_state->get('step') == 'views_form_views_form') { $form_state->disableRedirect(); } diff --git a/src/Plugin/views/filter/BoundaryFilter.php b/src/Plugin/views/filter/BoundaryFilter.php index f8cf854d4ffd369b082b3979bc59d90bebea2975..17074cbb90334f8a76248727cc22f31eba1e2ec8 100644 --- a/src/Plugin/views/filter/BoundaryFilter.php +++ b/src/Plugin/views/filter/BoundaryFilter.php @@ -85,6 +85,11 @@ class BoundaryFilter extends FilterPluginBase implements ContainerFactoryPluginI /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildExposeForm(&$form, FormStateInterface $form_state): void { @@ -145,6 +150,11 @@ class BoundaryFilter extends FilterPluginBase implements ContainerFactoryPluginI /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildExposedForm(&$form, FormStateInterface $form_state): void { parent::buildExposedForm($form, $form_state); @@ -243,6 +253,11 @@ class BoundaryFilter extends FilterPluginBase implements ContainerFactoryPluginI /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ protected function valueForm(&$form, FormStateInterface $form_state): void { parent::valueForm($form, $form_state); diff --git a/src/Plugin/views/filter/ProximityFilter.php b/src/Plugin/views/filter/ProximityFilter.php index c6da55ce2f72f2ed3c4ba40f1fb3d614a54757b1..bc251832f13f730c1b4365b1b9e50d2ac5528b65 100644 --- a/src/Plugin/views/filter/ProximityFilter.php +++ b/src/Plugin/views/filter/ProximityFilter.php @@ -61,6 +61,11 @@ class ProximityFilter extends NumericFilter implements ContainerFactoryPluginInt /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); @@ -92,6 +97,11 @@ class ProximityFilter extends NumericFilter implements ContainerFactoryPluginInt /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function groupForm(&$form, FormStateInterface $form_state): void { parent::groupForm($form, $form_state); @@ -106,6 +116,11 @@ class ProximityFilter extends NumericFilter implements ContainerFactoryPluginInt /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function valueForm(&$form, FormStateInterface $form_state): void { parent::valueForm($form, $form_state); @@ -139,6 +154,11 @@ class ProximityFilter extends NumericFilter implements ContainerFactoryPluginInt /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ protected function valueSubmit($form, FormStateInterface $form_state): void { $distance = (float) $form_state->getValue(['options', 'value', 'value']); @@ -155,6 +175,11 @@ class ProximityFilter extends NumericFilter implements ContainerFactoryPluginInt /** * {@inheritdoc} + * + * @param array $input + * Input. + * @param bool $status + * Status. */ public function storeExposedInput($input, $status): void { parent::storeExposedInput($input, $status); diff --git a/src/Plugin/views/sort/ProximitySort.php b/src/Plugin/views/sort/ProximitySort.php index cfa488eb85fbb10551832a63f452964d65636f61..ef1940c466cfb9b541cda5bcd71466ce40f9768d 100644 --- a/src/Plugin/views/sort/ProximitySort.php +++ b/src/Plugin/views/sort/ProximitySort.php @@ -17,7 +17,7 @@ class ProximitySort extends SortPluginBase { /** * {@inheritdoc} */ - public function query() { + public function query(): void { if (!($this->query instanceof Sql)) { return; } diff --git a/src/Plugin/views/style/CommonMap.php b/src/Plugin/views/style/CommonMap.php index 208381b533f35f31c789a4623eb2a8ea787a7fe4..3d4e68054b483f0707abd30f7ac379f9ca29666c 100644 --- a/src/Plugin/views/style/CommonMap.php +++ b/src/Plugin/views/style/CommonMap.php @@ -36,6 +36,8 @@ class CommonMap extends GeolocationStyleBase { /** * {@inheritdoc} + * + * @phpstan-ignore-next-line */ public function __construct( array $configuration, @@ -141,6 +143,11 @@ class CommonMap extends GeolocationStyleBase { /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { $map_provider_options = $this->mapProviderManager->getMapProviderOptions(); @@ -393,6 +400,7 @@ class CommonMap extends GeolocationStyleBase { '#id' => $this->mapId, '#settings' => $map_settings, '#context' => ['view' => $this->view], + '#attached' => [], ]; /* @@ -427,7 +435,7 @@ class CommonMap extends GeolocationStyleBase { ]; } - $build['#attached'] = BubbleableMetadata::mergeAttachments($build['#attached'] ?? [], [ + $build['#attached'] = BubbleableMetadata::mergeAttachments($build['#attached'], [ 'drupalSettings' => [ 'geolocation' => [ 'maps' => [ diff --git a/src/Plugin/views/style/GeolocationStyleBase.php b/src/Plugin/views/style/GeolocationStyleBase.php index c72637c860f62f751498b4dd1ed7462786900669..51fc29d466473d1abb350adc547335e60cc23ba5 100644 --- a/src/Plugin/views/style/GeolocationStyleBase.php +++ b/src/Plugin/views/style/GeolocationStyleBase.php @@ -60,6 +60,8 @@ abstract class GeolocationStyleBase extends StylePluginBase { /** * {@inheritdoc} + * + * @phpstan-ignore-next-line */ public function __construct(array $configuration, $plugin_id, $plugin_definition, $data_provider_manager, FileUrlGeneratorInterface $file_url_generator) { parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -164,6 +166,7 @@ abstract class GeolocationStyleBase extends StylePluginBase { '#attributes' => ['data-views-row-index' => $row->index], ]; + // @phpstan-ignore-next-line if ($row->_entity) { $location['#id'] = $row->_entity->getEntityTypeId() . '-' . $row->_entity->id() . '-' . $index; $location['#attributes']['data-entity-type'] = $row->_entity->getEntityTypeId(); @@ -219,6 +222,11 @@ abstract class GeolocationStyleBase extends StylePluginBase { /** * {@inheritdoc} + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); diff --git a/src/TypedData/GeolocationComputed.php b/src/TypedData/GeolocationComputed.php index 2ac2a450011c11730e37aace10b3c0b88fc13285..397c8a94b22ce58ee418d155ce7d76ee49ff69f5 100644 --- a/src/TypedData/GeolocationComputed.php +++ b/src/TypedData/GeolocationComputed.php @@ -46,7 +46,7 @@ class GeolocationComputed extends TypedData { /** * {@inheritdoc} */ - public function setValue($value, $notify = TRUE) { + public function setValue($value, $notify = TRUE): void { $this->value = (string) $value; // Notify the parent of any changes. diff --git a/tests/modules/geolocation_test_views/geolocation_test_views.install b/tests/modules/geolocation_test_views/geolocation_test_views.install index c2e6bb909c058add53568e02ed3a6db7d36645b1..558f976a0d5d5cba49a5af88e13cfd5b4dbb2660 100644 --- a/tests/modules/geolocation_test_views/geolocation_test_views.install +++ b/tests/modules/geolocation_test_views/geolocation_test_views.install @@ -8,7 +8,7 @@ /** * Implements hook_install(). */ -function geolocation_test_views_install() { +function geolocation_test_views_install(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_google_maps.settings'); if (empty($config->get('google_map_api_key'))) { @@ -19,7 +19,7 @@ function geolocation_test_views_install() { /** * Implements hook_uninstall(). */ -function geolocation_test_views_uninstall() { +function geolocation_test_views_uninstall(): void { /** @var \Drupal\Core\Config\Config $config */ $config = \Drupal::service('config.factory')->getEditable('geolocation_google_maps.settings'); if ($config->get('google_map_api_key') == 'AIzaSyAS0hYgEXBmvArc7_yXiK9lDrZ1O038weU') { diff --git a/tests/src/Functional/GeolocationFieldTest.php b/tests/src/Functional/GeolocationFieldTest.php index fb159734c72e98b64f6fc8015d128c6fb9068df3..a4f4889fa399294f3b363721febd12618962bf9c 100644 --- a/tests/src/Functional/GeolocationFieldTest.php +++ b/tests/src/Functional/GeolocationFieldTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\geolocation\Functional; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Tests\BrowserTestBase; +use Drupal\user\Entity\User; /** * Tests the creation of geolocation fields. @@ -16,7 +17,7 @@ class GeolocationFieldTest extends BrowserTestBase { /** * Modules to enable. * - * @var array + * @var string[] */ protected static $modules = [ 'field', @@ -28,19 +29,11 @@ class GeolocationFieldTest extends BrowserTestBase { ]; /** - * {@inheritdoc} - */ - protected $field; - - /** - * {@inheritdoc} - */ - protected $webUser; - - /** - * {@inheritdoc} + * Article creator. + * + * @var \Drupal\user\Entity\User */ - protected $articleCreator; + protected User $articleCreator; /** * {@inheritdoc} @@ -63,7 +56,7 @@ class GeolocationFieldTest extends BrowserTestBase { /** * Helper function for testGeolocationField(). */ - public function testGeolocationFieldLatlngWidget() { + public function testGeolocationFieldLatlngWidget(): void { EntityFormDisplay::load('node.geolocation_default_article.default') ->setComponent('field_geolocation_demo_single', [ 'type' => 'geolocation_latlng', diff --git a/tests/src/Functional/GeolocationSchemaCoverageTest.php b/tests/src/Functional/GeolocationSchemaCoverageTest.php index fd7fe3750ed50088db8a8e8dcd2c2d15cb85f1a4..b6595bfebc235378341fcc9ab1a584d3fac556f2 100644 --- a/tests/src/Functional/GeolocationSchemaCoverageTest.php +++ b/tests/src/Functional/GeolocationSchemaCoverageTest.php @@ -39,7 +39,7 @@ class GeolocationSchemaCoverageTest extends BrowserTestBase { /** * Test MapProviders. */ - public function testMapProvidersDefaults() { + public function testMapProvidersDefaults(): void { /** @var \Drupal\geolocation\MapProviderManager $mapProviderManager */ $mapProviderManager = \Drupal::service('plugin.manager.geolocation.mapprovider'); $mapProviderIds = $mapProviderManager->getDefinitions(); @@ -62,7 +62,7 @@ class GeolocationSchemaCoverageTest extends BrowserTestBase { /** * Test MapFeatures with providers. */ - public function testMapProvidersWithMapFeatures() { + public function testMapProvidersWithMapFeatures(): void { /** @var \Drupal\geolocation\MapFeatureManager $mapFeatureManager */ $mapFeatureManager = \Drupal::service('plugin.manager.geolocation.mapfeature'); diff --git a/tests/src/Functional/GeolocationViewsBoundaryTest.php b/tests/src/Functional/GeolocationViewsBoundaryTest.php index 2ccb0d2d11ff9904e52afa29ab720e5cf01906c7..6764abc263a1cb9d10faa30ec7aa267009ce8a16 100644 --- a/tests/src/Functional/GeolocationViewsBoundaryTest.php +++ b/tests/src/Functional/GeolocationViewsBoundaryTest.php @@ -28,7 +28,7 @@ class GeolocationViewsBoundaryTest extends BrowserTestBase { * * @var string */ - protected $viewsPath = 'geolocation-demo/boundary-filter-fixed-values'; + protected string $viewsPath = 'geolocation-demo/boundary-filter-fixed-values'; /** * {@inheritdoc} @@ -38,7 +38,7 @@ class GeolocationViewsBoundaryTest extends BrowserTestBase { /** * Tests the boundary filter. */ - public function testBoundaryNoLocations() { + public function testBoundaryNoLocations(): void { $this->drupalGet($this->viewsPath); $this->assertSession()->statusCodeEquals(200); } @@ -48,7 +48,7 @@ class GeolocationViewsBoundaryTest extends BrowserTestBase { * * It's currently locked to filter boundary of NE80,80 to SW20,20. */ - public function testBoundaryLocations() { + public function testBoundaryLocations(): void { $entity_test_storage = \Drupal::entityTypeManager()->getStorage('node'); $entity_test_storage->create([ diff --git a/tests/src/Functional/GeolocationViewsCommonMapTest.php b/tests/src/Functional/GeolocationViewsCommonMapTest.php index 2113b7ffc941fb0fa1f785ec8b6a344e528d547f..4110ce59c8c9dc9b7782a155803f3e45be8a3c27 100644 --- a/tests/src/Functional/GeolocationViewsCommonMapTest.php +++ b/tests/src/Functional/GeolocationViewsCommonMapTest.php @@ -33,7 +33,7 @@ class GeolocationViewsCommonMapTest extends BrowserTestBase { /** * Tests the boundary filter. */ - public function testStaticCommonMap() { + public function testStaticCommonMap(): void { $this->drupalGet('geolocation-demo/common-map'); $this->assertSession()->statusCodeEquals(200); } @@ -41,7 +41,7 @@ class GeolocationViewsCommonMapTest extends BrowserTestBase { /** * Tests the boundary filter. */ - public function testAjaxCommonMap() { + public function testAjaxCommonMap(): void { $this->drupalGet('geolocation-demo/common-map-ajax'); $this->assertSession()->statusCodeEquals(200); } diff --git a/tests/src/Functional/GeolocationViewsProximityArgumentTest.php b/tests/src/Functional/GeolocationViewsProximityArgumentTest.php index ce9dcee1ea8b485e139ef17e8a314dbed7a3af68..e6b0e7fee2e788a05d859ef2c9acbdfa0d8c38a0 100644 --- a/tests/src/Functional/GeolocationViewsProximityArgumentTest.php +++ b/tests/src/Functional/GeolocationViewsProximityArgumentTest.php @@ -28,7 +28,7 @@ class GeolocationViewsProximityArgumentTest extends BrowserTestBase { * * @var string */ - protected $viewsPath = 'geolocation-demo/proximity_argument_and_sort'; + protected string $viewsPath = 'geolocation-demo/proximity_argument_and_sort'; /** * {@inheritdoc} @@ -38,7 +38,7 @@ class GeolocationViewsProximityArgumentTest extends BrowserTestBase { /** * Tests the CommonMap style. */ - public function testProximityNoLocations() { + public function testProximityNoLocations(): void { $this->drupalGet($this->viewsPath); $this->assertSession()->statusCodeEquals(200); } @@ -46,7 +46,7 @@ class GeolocationViewsProximityArgumentTest extends BrowserTestBase { /** * Tests the CommonMap style. */ - public function testNoProximityLocations() { + public function testNoProximityLocations(): void { $entity_test_storage = \Drupal::entityTypeManager()->getStorage('node'); $entity_test_storage->create([ @@ -112,7 +112,7 @@ class GeolocationViewsProximityArgumentTest extends BrowserTestBase { /** * Tests to ensure rounding error doesn't occur (d.o #2796999). */ - public function testRoundingError() { + public function testRoundingError(): void { $entity_test_storage = \Drupal::entityTypeManager()->getStorage('node'); $entity_test_storage->create([ @@ -134,7 +134,7 @@ class GeolocationViewsProximityArgumentTest extends BrowserTestBase { /** * Tests to ensure views argument is parsed correctly (d.o #2856948) */ - public function testArgumentParse() { + public function testArgumentParse(): void { $entity_test_storage = \Drupal::entityTypeManager()->getStorage('node'); $entity_test_storage->create([ diff --git a/tests/src/Functional/GeolocationViewsProximityByEntityTest.php b/tests/src/Functional/GeolocationViewsProximityByEntityTest.php index b1cf0b7f3f92a4ee97143a83033b59c66b27f9c4..97c8fc6a1a0b20c82e339d4832ad54ed80af1cf4 100644 --- a/tests/src/Functional/GeolocationViewsProximityByEntityTest.php +++ b/tests/src/Functional/GeolocationViewsProximityByEntityTest.php @@ -31,7 +31,7 @@ class GeolocationViewsProximityByEntityTest extends BrowserTestBase { /** * Tests the proximity sort. */ - public function testEmpty() { + public function testEmpty(): void { $this->drupalGet('geolocation-demo/proximity-by-entity-id/'); $this->assertSession()->statusCodeEquals(200); @@ -42,7 +42,7 @@ class GeolocationViewsProximityByEntityTest extends BrowserTestBase { /** * Tests the proximity sort. */ - public function testProximityByEntity() { + public function testProximityByEntity(): void { /** @var \Drupal\node\NodeStorageInterface $entity_test_storage */ $entity_test_storage = \Drupal::entityTypeManager()->getStorage('node'); diff --git a/tests/src/Functional/GeolocationViewsSettingsTest.php b/tests/src/Functional/GeolocationViewsSettingsTest.php index c96caf58c303ddc815f84850e05677933ed57222..6400f7e88cb091d2e277a5b1d0be983742d61a20 100644 --- a/tests/src/Functional/GeolocationViewsSettingsTest.php +++ b/tests/src/Functional/GeolocationViewsSettingsTest.php @@ -36,7 +36,7 @@ class GeolocationViewsSettingsTest extends BrowserTestBase { /** * Tests the Views admin UI and field handlers. */ - public function testViewsMapSettings() { + public function testViewsMapSettings(): void { $permissions = [ 'access administration pages', 'administer views', @@ -57,7 +57,7 @@ class GeolocationViewsSettingsTest extends BrowserTestBase { /** * Tests the Views admin UI and field handlers. */ - public function testViewsProximitySettings() { + public function testViewsProximitySettings(): void { $permissions = [ 'access administration pages', 'administer views', diff --git a/tests/src/FunctionalJavascript/GeolocationCommonMapAjaxJavascriptTest.php b/tests/src/FunctionalJavascript/GeolocationCommonMapAjaxJavascriptTest.php index dcbae2c6ffbc04275f5b7b90b2121fa3ab9f7928..ec9f782288395c80ba7255010e8289cba86fef57 100644 --- a/tests/src/FunctionalJavascript/GeolocationCommonMapAjaxJavascriptTest.php +++ b/tests/src/FunctionalJavascript/GeolocationCommonMapAjaxJavascriptTest.php @@ -34,7 +34,7 @@ class GeolocationCommonMapAjaxJavascriptTest extends GeolocationJavascriptTestBa * * @var array */ - public static $testViews = ['geolocation_common_map_ajax_test']; + public static array $testViews = ['geolocation_common_map_ajax_test']; /** * {@inheritdoc} @@ -110,7 +110,7 @@ class GeolocationCommonMapAjaxJavascriptTest extends GeolocationJavascriptTestBa /** * Tests the CommonMap style. */ - public function testCommonMap() { + public function testCommonMap(): void { $this->drupalGet('geolocation-common-map-ajax-test'); $this->assertSession()->elementExists('css', '.geolocation-map-container'); @@ -126,7 +126,7 @@ class GeolocationCommonMapAjaxJavascriptTest extends GeolocationJavascriptTestBa /** * Tests the CommonMap style. */ - public function testCommonMapAjax() { + public function testCommonMapAjax(): void { $this->drupalGet('geolocation-common-map-ajax-test'); $session = $this->getSession(); diff --git a/tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php b/tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php index dcf136a5adef5658576029634d3f04205d0862d0..29777ca929dab6513d700761fe1fb4990b919b32 100644 --- a/tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php +++ b/tests/src/FunctionalJavascript/GeolocationGoogleGeocoderWidgetTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\user\Entity\User; /** * Tests the Google Geocoder Widget functionality. @@ -15,9 +16,11 @@ use Drupal\field\Entity\FieldStorageConfig; class GeolocationGoogleGeocoderWidgetTest extends GeolocationJavascriptTestBase { /** - * {@inheritdoc} + * Admin User. + * + * @var \Drupal\user\Entity\User */ - public $adminUser; + public User $adminUser; /** * {@inheritdoc} @@ -123,7 +126,7 @@ class GeolocationGoogleGeocoderWidgetTest extends GeolocationJavascriptTestBase /** * Tests the Google Maps widget. */ - public function testGeocoderWidgetMapPresent() { + public function testGeocoderWidgetMapPresent(): void { $this->drupalLogin($this->adminUser); $this->drupalGet('node/3/edit'); @@ -140,7 +143,7 @@ class GeolocationGoogleGeocoderWidgetTest extends GeolocationJavascriptTestBase /** * Tests the Google Maps widget. */ - public function testGeocoderWidgetEmptyValuePreserved() { + public function testGeocoderWidgetEmptyValuePreserved(): void { EntityFormDisplay::load('node.article.default') ->setComponent('field_geolocation', [ 'type' => 'geolocation_map', diff --git a/tests/src/FunctionalJavascript/GeolocationJavascriptTest.php b/tests/src/FunctionalJavascript/GeolocationJavascriptTest.php index 92e58f61d3e1d70127211b81ab844e3af458ad13..4ff9d817ffd560f7401073fa8c04f41446fb14d8 100644 --- a/tests/src/FunctionalJavascript/GeolocationJavascriptTest.php +++ b/tests/src/FunctionalJavascript/GeolocationJavascriptTest.php @@ -36,7 +36,7 @@ class GeolocationJavascriptTest extends GeolocationJavascriptTestBase { * * @var array */ - public static $testViews = ['geolocation_test']; + public static array $testViews = ['geolocation_test']; /** * {@inheritdoc} @@ -136,7 +136,7 @@ class GeolocationJavascriptTest extends GeolocationJavascriptTestBase { * * Changes the language to French, checking for the French map. */ - public function testGoogleMapUsingCurrentLanguage() { + public function testGoogleMapUsingCurrentLanguage(): void { // Log in as an administrator and change geolocation and language settings. $admin_user = $this->drupalCreateUser([ 'configure geolocation', @@ -185,7 +185,7 @@ class GeolocationJavascriptTest extends GeolocationJavascriptTestBase { /** * Tests the CommonMap style. */ - public function testCommonMap() { + public function testCommonMap(): void { $this->drupalGet('geolocation-test'); $this->assertSession()->elementExists('css', '.geolocation-map-container'); @@ -201,7 +201,7 @@ class GeolocationJavascriptTest extends GeolocationJavascriptTestBase { /** * Tests the Google Maps formatter. */ - public function testGoogleMapFormatter() { + public function testGoogleMapFormatter(): void { $this->drupalGet('node/3'); $this->assertSession()->elementExists('css', '.geolocation-map-container'); @@ -216,7 +216,7 @@ class GeolocationJavascriptTest extends GeolocationJavascriptTestBase { /** * Tests the Google Maps formatter. */ - public function testGoogleMapFormatterCustomSettings() { + public function testGoogleMapFormatterCustomSettings(): void { $this->drupalGet('node/4'); $this->assertSession()->elementExists('css', '.geolocation-map-container'); diff --git a/tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php b/tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php index c647a1280dd17d586532688889a3efccf55d371d..9c4fde4f2e2c7f34bba182e841d501e78b336319 100644 --- a/tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php +++ b/tests/src/FunctionalJavascript/GeolocationLeafletJavascriptTest.php @@ -34,7 +34,7 @@ class GeolocationLeafletJavascriptTest extends GeolocationJavascriptTestBase { * * @var array */ - public static $testViews = ['geolocation_leaflet_test']; + public static array $testViews = ['geolocation_leaflet_test']; /** * {@inheritdoc} @@ -110,7 +110,7 @@ class GeolocationLeafletJavascriptTest extends GeolocationJavascriptTestBase { /** * Tests the CommonMap style. */ - public function testLeafletMap() { + public function testLeafletMap(): void { $this->drupalGet('geolocation-leaflet-test'); $this->assertSession()->elementExists('css', '.geolocation-map-container'); diff --git a/tests/src/FunctionalJavascript/GeolocationTokenFormatterTest.php b/tests/src/FunctionalJavascript/GeolocationTokenFormatterTest.php index bc1ba1b1a54c331672d6b00ef3c1c949b79192ff..d20f6ca3b09e10f9af6de20c98c1cb94299e2d8c 100644 --- a/tests/src/FunctionalJavascript/GeolocationTokenFormatterTest.php +++ b/tests/src/FunctionalJavascript/GeolocationTokenFormatterTest.php @@ -79,7 +79,7 @@ class GeolocationTokenFormatterTest extends GeolocationJavascriptTestBase { /** * Tests the token formatter. */ - public function testGeocoderTokenizedTestReplacement() { + public function testGeocoderTokenizedTestReplacement(): void { $this->drupalGet('node/1'); $this->assertSession()->responseContains('<span class="geolocation-latlng">52, 47</span>'); diff --git a/tests/src/Kernel/GeolocationItemTest.php b/tests/src/Kernel/GeolocationItemTest.php index 9d9b315ee0e836f6beb85f9a79bf2d8a684e7da4..ef1a7a1bbe92c4b091713a1c5c891338d67eecb0 100644 --- a/tests/src/Kernel/GeolocationItemTest.php +++ b/tests/src/Kernel/GeolocationItemTest.php @@ -45,13 +45,13 @@ class GeolocationItemTest extends FieldKernelTestBase { /** * Tests using entity fields of the geolocation field type. */ - public function testGeolocationItem() { + public function testGeolocationItem(): void { $entityTestStorage = \Drupal::entityTypeManager()->getStorage('entity_test'); - $lat = '49.880657'; - $lng = '10.869212'; + $lat = 49.880657; + $lng = 10.869212; $data = 'Foo bar'; - // Verify entity creation. + /** @var \Drupal\entity_test\Entity\EntityTest $entity */ $entity = $entityTestStorage->create([ 'title' => $this->randomMachineName(), 'field_test' => [ @@ -64,39 +64,43 @@ class GeolocationItemTest extends FieldKernelTestBase { // Verify entity has been created properly. $id = $entity->id(); + /** @var \Drupal\entity_test\Entity\EntityTest $entity */ $entity = $entityTestStorage->load($id); $this->assertInstanceOf(FieldItemListInterface::class, $entity->get('field_test'), 'Field implements interface.'); $this->assertInstanceOf(FieldItemInterface::class, $entity->get('field_test')[0], 'Field item implements interface.'); - $this->assertEquals($entity->get('field_test')->lat, $lat, "Lat {$entity->get('field_test')->lat} is equal to lat {$lat}."); - $this->assertEquals($entity->get('field_test')[0]->lat, $lat, "Lat {$entity->get('field_test')[0]->lat} is equal to lat {$lat}."); - $this->assertEquals($entity->get('field_test')->lng, $lng, "Lng {$entity->get('field_test')->lng} is equal to lng {$lng}."); - $this->assertEquals($entity->get('field_test')[0]->lng, $lng, "Lng {$entity->get('field_test')[0]->lng} is equal to lng {$lng}."); - $this->assertEquals(round($entity->get('field_test')->lat_sin, 5), round(sin(deg2rad($lat)), 5), "Sine for latitude calculated correctly."); - $this->assertEquals(round($entity->get('field_test')->lat_cos, 5), round(cos(deg2rad($lat)), 5), "Cosine for latitude calculated correctly."); - $this->assertEquals(round($entity->get('field_test')->lng_rad, 5), round(deg2rad($lng), 5), "Radian value for longitude calculated correctly."); + /** @var \Drupal\geolocation\GeolocationItemListInterface $field_item */ + $field_item = $entity->get('field_test'); + + $this->assertEquals($field_item->lat, $lat, "Lat $field_item->lat is equal to lat $lat."); + $this->assertEquals($field_item[0]->lat, $lat, "Lat {$field_item[0]->lat} is equal to lat $lat."); + $this->assertEquals($field_item->lng, $lng, "Lng $field_item->lng is equal to lng $lng."); + $this->assertEquals($field_item[0]->lng, $lng, "Lng {$field_item[0]->lng} is equal to lng $lng."); - $this->assertEquals($entity->get('field_test')->data, $data, "Data {$entity->get('field_test')->data} is equal to data {$data}."); + $this->assertEquals(round($field_item->lat_sin, 5), round(sin(deg2rad($lat)), 5), "Sine for latitude calculated correctly."); + $this->assertEquals(round($field_item->lat_cos, 5), round(cos(deg2rad($lat)), 5), "Cosine for latitude calculated correctly."); + $this->assertEquals(round($field_item->lng_rad, 5), round(deg2rad($lng), 5), "Radian value for longitude calculated correctly."); + + $this->assertEquals($field_item->data, $data, "Data $field_item->data is equal to data $data."); // Verify changing the field value. $new_lat = rand(-90, 90) - rand(0, 999999) / 1000000; $new_lng = rand(-180, 180) - rand(0, 999999) / 1000000; $new_data = ['an_array']; - $entity->get('field_test')->lat = $new_lat; - $entity->get('field_test')->lng = $new_lng; - $entity->get('field_test')->data = $new_data; - $this->assertEquals($entity->get('field_test')->lat, $new_lat, "Lat {$entity->get('field_test')->lat} is equal to new lat {$new_lat}."); - $this->assertEquals($entity->get('field_test')->lng, $new_lng, "Lng {$entity->get('field_test')->lng} is equal to new lng {$new_lng}."); - $this->assertEquals($entity->get('field_test')->data, $new_data, "Data is correctly updated to new data."); + $field_item->lat = $new_lat; + $field_item->lng = $new_lng; + $field_item->data = $new_data; // Assert that the calculated properties were updated. - $this->assertEquals(round($entity->get('field_test')->lat_sin, 5), round(sin(deg2rad($new_lat)), 5), "Sine for latitude calculated correctly after change."); - $this->assertEquals(round($entity->get('field_test')->lat_cos, 5), round(cos(deg2rad($new_lat)), 5), "Cosine for latitude calculated correctly after change."); - $this->assertEquals(round($entity->get('field_test')->lng_rad, 5), round(deg2rad($new_lng), 5), "Radian value for longitude calculated correctly after change."); + $this->assertEquals(round($field_item->lat_sin, 5), round(sin(deg2rad($new_lat)), 5), "Sine for latitude calculated correctly after change."); + $this->assertEquals(round($field_item->lat_cos, 5), round(cos(deg2rad($new_lat)), 5), "Cosine for latitude calculated correctly after change."); + $this->assertEquals(round($field_item->lng_rad, 5), round(deg2rad($new_lng), 5), "Radian value for longitude calculated correctly after change."); // Do the same by setting the values as an array. $entityTestStorage->resetCache([$id]); + + /** @var \Drupal\entity_test\Entity\EntityTest $entity */ $entity = $entityTestStorage->load($id); $entity->set('field_test', [ @@ -105,26 +109,35 @@ class GeolocationItemTest extends FieldKernelTestBase { 'data' => $new_data, ]); - $this->assertEquals($entity->get('field_test')->lat, $new_lat, "Lat {$entity->get('field_test')->lat} is equal to new lat {$new_lat}."); - $this->assertEquals($entity->get('field_test')->lng, $new_lng, "Lng {$entity->get('field_test')->lng} is equal to new lng {$new_lng}."); - $this->assertEquals($entity->get('field_test')->data, $new_data, "Data is correctly updated to new data."); + /** @var \Drupal\geolocation\GeolocationItemListInterface $field_item */ + $field_item = $entity->get('field_test'); + + $this->assertEquals($field_item->lat, $new_lat, "Lat $field_item->lat is equal to new lat $new_lat."); + $this->assertEquals($field_item->lng, $new_lng, "Lng $field_item->lng is equal to new lng $new_lng."); + $this->assertEquals($field_item->data, $new_data, "Data is correctly updated to new data."); // Assert that the calculated properties were updated. - $this->assertEquals(round($entity->get('field_test')->lat_sin, 5), round(sin(deg2rad($new_lat)), 5), "Sine for latitude calculated correctly after change."); - $this->assertEquals(round($entity->get('field_test')->lat_cos, 5), round(cos(deg2rad($new_lat)), 5), "Cosine for latitude calculated correctly after change."); - $this->assertEquals(round($entity->get('field_test')->lng_rad, 5), round(deg2rad($new_lng), 5), "Radian value for longitude calculated correctly after change."); + $this->assertEquals(round($field_item->lat_sin, 5), round(sin(deg2rad($new_lat)), 5), "Sine for latitude calculated correctly after change."); + $this->assertEquals(round($field_item->lat_cos, 5), round(cos(deg2rad($new_lat)), 5), "Cosine for latitude calculated correctly after change."); + $this->assertEquals(round($field_item->lng_rad, 5), round(deg2rad($new_lng), 5), "Radian value for longitude calculated correctly after change."); // Read changed entity and assert changed values. $entity->save(); + + /** @var \Drupal\entity_test\Entity\EntityTest $entity */ $entity = $entityTestStorage->load($id); - $this->assertEquals($entity->get('field_test')->lat, $new_lat, "Lat {$entity->get('field_test')->lat} is equal to new lat {$new_lat}."); - $this->assertEquals($entity->get('field_test')->lng, $new_lng, "Lng {$entity->get('field_test')->lng} is equal to new lng {$new_lng}."); - $this->assertEquals(round($entity->get('field_test')->lat_sin, 5), round(sin(deg2rad($new_lat)), 5), "Sine for latitude calculated correctly after change."); - $this->assertEquals(round($entity->get('field_test')->lat_cos, 5), round(cos(deg2rad($new_lat)), 5), "Cosine for latitude calculated correctly after change."); - $this->assertEquals(round($entity->get('field_test')->lng_rad, 5), round(deg2rad($new_lng), 5), "Radian value for longitude calculated correctly after change."); + /** @var \Drupal\geolocation\GeolocationItemListInterface $field_item */ + $field_item = $entity->get('field_test'); + + $this->assertEquals($field_item->lat, $new_lat, "Lat $field_item->lat is equal to new lat $new_lat."); + $this->assertEquals($field_item->lng, $new_lng, "Lng $field_item->lng is equal to new lng $new_lng."); + + $this->assertEquals(round($field_item->lat_sin, 5), round(sin(deg2rad($new_lat)), 5), "Sine for latitude calculated correctly after change."); + $this->assertEquals(round($field_item->lat_cos, 5), round(cos(deg2rad($new_lat)), 5), "Cosine for latitude calculated correctly after change."); + $this->assertEquals(round($field_item->lng_rad, 5), round(deg2rad($new_lng), 5), "Radian value for longitude calculated correctly after change."); - $this->assertEquals($entity->get('field_test')->data, $new_data, "Data is correctly updated to new data."); + $this->assertEquals($field_item->data, $new_data, "Data is correctly updated to new data."); } }