diff --git a/address.module b/address.module index e6a3c46d1bff00359394cd7520a283e54fa04507..239590a63aef1ef1ede1d8d8f9645c873b1d8485 100644 --- a/address.module +++ b/address.module @@ -7,7 +7,7 @@ use Drupal\Core\Form\FormStateInterface; - /** +/** * Implements hook_form_BASE_FORM_ID_alter(). * * Removes the default values form from the field settings page. @@ -43,7 +43,7 @@ function address_theme() { 'administrative_area' => [], 'country' => [], ], - ] + ], ]; } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..aef05f516f1e75bd7614c248f914182860c075b8 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,43 @@ + + + Drupal 8 coding standards + + */.git/* + */config/* + */css/* + */js/* + */icons/* + */vendor/* + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + 0 + + + + 0 + + + 0 + + + + 0 + + + diff --git a/src/Annotation/ZoneMember.php b/src/Annotation/ZoneMember.php index fe9ed35bd77a76bb0565ec1daa5c76f955072c13..4861c8b900873f276c1607bd6782b3fc4a0fbdb0 100644 --- a/src/Annotation/ZoneMember.php +++ b/src/Annotation/ZoneMember.php @@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Plugin; /** * Defines a zone member annotation object. * - * Plugin Namespace: Plugin\ZoneMember + * Plugin Namespace: Plugin\ZoneMember. * * @Annotation */ @@ -30,4 +30,3 @@ class ZoneMember extends Plugin { public $name; } - diff --git a/src/Element/Address.php b/src/Element/Address.php index bab63c02c59f81251a7a5387b5000ea5fdeaf8c1..903fe1a16aad9b76be38f90dc7d34d0f27825655 100644 --- a/src/Element/Address.php +++ b/src/Element/Address.php @@ -117,7 +117,7 @@ class Address extends FormElement { * @throws \InvalidArgumentException * Thrown when #available_countries or #used_fields is malformed. */ - public static function processAddress(&$element, FormStateInterface $form_state, &$complete_form) { + public static function processAddress(array &$element, FormStateInterface $form_state, array &$complete_form) { if (isset($element['#available_countries']) && !is_array($element['#available_countries'])) { throw new \InvalidArgumentException('The #available_countries property must be an array.'); } @@ -222,7 +222,8 @@ class Address extends FormElement { $locale = \Drupal::languageManager()->getConfigOverrideLanguage()->getId(); if (LocaleHelper::match($address_format->getLocale(), $locale)) { $format_string = $address_format->getLocalFormat(); - } else { + } + else { $format_string = $address_format->getFormat(); } $grouped_fields = AddressFormatHelper::getGroupedFields($format_string); @@ -400,5 +401,4 @@ class Address extends FormElement { return $element; } - } diff --git a/src/Entity/ZoneInterface.php b/src/Entity/ZoneInterface.php index 7caf4b76cb43462194109f316c40c82281f13a5d..da9a0b6c35bf0e8f613c6f96f45e00b4564135a2 100644 --- a/src/Entity/ZoneInterface.php +++ b/src/Entity/ZoneInterface.php @@ -71,7 +71,8 @@ interface ZoneInterface extends ExternalZoneInterface, ConfigEntityInterface, En * @param \Drupal\address\Plugin\ZoneMember\ZoneMemberInterface $member * The zone member. * - * @return bool TRUE if the zone member was found, FALSE otherwise. + * @return bool + * TRUE if the zone member was found, FALSE otherwise. */ public function hasMember(ZoneMemberInterface $member); diff --git a/src/FieldHelper.php b/src/FieldHelper.php index 13368a46ba1c006ef5eb41a2ed4054981e4bc63e..f4a7b300eaf5480ad2322716463e6725385a5af9 100644 --- a/src/FieldHelper.php +++ b/src/FieldHelper.php @@ -39,7 +39,7 @@ class FieldHelper { /** * Gets the autocomplete attribute for the given AddressField value. * - * Source: https://html.spec.whatwg.org/multipage/forms.html#autofill + * Source: https://html.spec.whatwg.org/multipage/forms.html#autofill. * * @param string $field * An AddressField value. diff --git a/src/Form/ZoneForm.php b/src/Form/ZoneForm.php index 441411a37d90ce792bbe8f7a8f3a08b57756bf24..3f079be7e6b9caa71f27019ba9903cd09019efb5 100644 --- a/src/Form/ZoneForm.php +++ b/src/Form/ZoneForm.php @@ -226,7 +226,7 @@ class ZoneForm extends EntityForm { /** * Validation callback for the embedded zone member form. */ - public function memberFormValidate($member_form, FormStateInterface $form_state) { + public function memberFormValidate(array $member_form, FormStateInterface $form_state) { /** @var \Drupal\address\Plugin\ZoneMember\ZoneMemberInterface $member */ $member = $member_form['#member']; $member_form_state = $this->buildMemberFormState($member_form['#parents'], $form_state); @@ -283,7 +283,7 @@ class ZoneForm extends EntityForm { * @return \Drupal\Core\Form\FormStateInterface * The new member form state. */ - protected function buildMemberFormState($member_parents, FormStateInterface $form_state) { + protected function buildMemberFormState(array $member_parents, FormStateInterface $form_state) { $member_values = $form_state->getValue($member_parents, []); $member_user_input = (array) NestedArray::getValue($form_state->getUserInput(), $member_parents); $member_form_state = new FormState(); diff --git a/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php b/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php index f7f14e607d59e90c37c45b67e7a3bdfea7430f92..cf88250b714bfcbb72b5d7640f3ee3ea4bc8b495 100644 --- a/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php +++ b/src/Plugin/Field/FieldFormatter/AddressDefaultFormatter.php @@ -201,7 +201,8 @@ class AddressDefaultFormatter extends FormatterBase implements ContainerFactoryP // depending on whether the format is minor-to-major or major-to-minor. if (LocaleHelper::match($address_format->getLocale(), $locale)) { $format_string = '%country' . "\n" . $address_format->getLocalFormat(); - } else { + } + else { $format_string = $address_format->getFormat() . "\n" . '%country'; } diff --git a/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php b/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php index 31bce94f7114b13060f818bf51ba63f99e16800c..cb6c924f804ecfca6216dc4ccf9291b42fd0f034 100644 --- a/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php +++ b/src/Plugin/Field/FieldFormatter/AddressPlainFormatter.php @@ -14,7 +14,6 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Render\Element; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/src/Plugin/Field/FieldWidget/AddressDefaultWidget.php b/src/Plugin/Field/FieldWidget/AddressDefaultWidget.php index ea3deb9b1c67855a0866a6f52b6f7c2a8050dd51..5f4b6fb27cc471151ffe03a19835233b4dd1e4c7 100644 --- a/src/Plugin/Field/FieldWidget/AddressDefaultWidget.php +++ b/src/Plugin/Field/FieldWidget/AddressDefaultWidget.php @@ -2,7 +2,6 @@ namespace Drupal\address\Plugin\Field\FieldWidget; -use CommerceGuys\Addressing\AddressFormat\AddressField; use CommerceGuys\Addressing\Country\CountryRepositoryInterface; use Drupal\address\Event\AddressEvents; use Drupal\address\Event\InitialValuesEvent; @@ -13,7 +12,6 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Render\Element; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Validator\ConstraintViolationInterface; diff --git a/src/Plugin/Validation/Constraint/AddressFormatConstraint.php b/src/Plugin/Validation/Constraint/AddressFormatConstraint.php index 5dbc9ab605c3bf8f5a56fb311f54c96d7527068f..cb9a83f535fda90f9771538e0273ef2fbbd7cf3c 100644 --- a/src/Plugin/Validation/Constraint/AddressFormatConstraint.php +++ b/src/Plugin/Validation/Constraint/AddressFormatConstraint.php @@ -22,7 +22,7 @@ class AddressFormatConstraint extends Constraint { public $invalidMessage = '@name field is not in the right format.'; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct($options = NULL) { parent::__construct($options); @@ -34,7 +34,7 @@ class AddressFormatConstraint extends Constraint { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getTargets() { return self::CLASS_CONSTRAINT; diff --git a/src/Plugin/Validation/Constraint/CountryConstraintValidator.php b/src/Plugin/Validation/Constraint/CountryConstraintValidator.php index ee436a037ecdf93f46d9223e44ef5d16181126b3..95d39b5e0ffbd3fed576965bb951dda6e9d98042 100644 --- a/src/Plugin/Validation/Constraint/CountryConstraintValidator.php +++ b/src/Plugin/Validation/Constraint/CountryConstraintValidator.php @@ -63,11 +63,11 @@ class CountryConstraintValidator extends ConstraintValidator implements Containe } $available_countries = $constraint->availableCountries; - if (!empty($available_countries) && !in_array($country_code, $available_countries)) { - $this->context->buildViolation($constraint->notAvailableMessage) - ->atPath('country_code') - ->setParameter('%value', $this->formatValue($country_code)) - ->addViolation(); + if (!empty($available_countries) && !in_array($country_code, $available_countries)) { + $this->context->buildViolation($constraint->notAvailableMessage) + ->atPath('country_code') + ->setParameter('%value', $this->formatValue($country_code)) + ->addViolation(); } } diff --git a/src/Plugin/ZoneMember/ZoneMemberCountry.php b/src/Plugin/ZoneMember/ZoneMemberCountry.php index dd62a9cb553e1772db491ba66291dc6616fcdfc3..f4a67eca210d043912cc98eaa3e20369906b1926 100644 --- a/src/Plugin/ZoneMember/ZoneMemberCountry.php +++ b/src/Plugin/ZoneMember/ZoneMemberCountry.php @@ -152,7 +152,7 @@ class ZoneMemberCountry extends ZoneMemberBase implements ContainerFactoryPlugin * @param array $values * The form values. * @param \CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format - * The address format for the selected country. + * The address format for the selected country. * * @return array * The form with the added subdivision elements. @@ -209,7 +209,7 @@ class ZoneMemberCountry extends ZoneMemberBase implements ContainerFactoryPlugin * @param array $values * The form values. * @param \CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format - * The address format for the selected country. + * The address format for the selected country. * * @return array * The form with the added postal code elements. @@ -289,8 +289,8 @@ class ZoneMemberCountry extends ZoneMemberBase implements ContainerFactoryPlugin } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function match(AddressInterface $address) { if ($address->getCountryCode() != $this->configuration['country_code']) { return FALSE; diff --git a/src/Plugin/ZoneMember/ZoneMemberInterface.php b/src/Plugin/ZoneMember/ZoneMemberInterface.php index f1b799bbb4fbb3237b7b9f77685db716611e88bc..cf2f4777badf53443019a6448ab967db4a14c790 100644 --- a/src/Plugin/ZoneMember/ZoneMemberInterface.php +++ b/src/Plugin/ZoneMember/ZoneMemberInterface.php @@ -14,7 +14,8 @@ interface ZoneMemberInterface extends ExternalZoneMemberInterface, ConfigurableP /** * Gets the zone member weight. * - * @return string The zone member weight. + * @return string + * The zone member weight. */ public function getWeight(); diff --git a/src/Plugin/migrate/process/AddressField.php b/src/Plugin/migrate/process/AddressField.php index dec98ab9c8c3b7118db24251efd5112b27473869..4db7de529d49703dc9d7ea89443663fc60a74db2 100644 --- a/src/Plugin/migrate/process/AddressField.php +++ b/src/Plugin/migrate/process/AddressField.php @@ -37,7 +37,7 @@ class AddressField extends ProcessPluginBase { elseif (!empty($value['name_line'])) { $split = explode(" ", $value['name_line']); $parsed['given_name'] = array_shift($split); - $parsed['family_name'] = implode(" ", $split); + $parsed['family_name'] = implode(' ', $split); } return $parsed; } diff --git a/src/Plugin/views/field/Subdivision.php b/src/Plugin/views/field/Subdivision.php index d8d90f0ec8828d43076b82335660e69576c501b9..fe1939b003595a47400785eb3162ea8f3dea63c6 100644 --- a/src/Plugin/views/field/Subdivision.php +++ b/src/Plugin/views/field/Subdivision.php @@ -73,6 +73,7 @@ class Subdivision extends FieldPluginBase { $address->getCountryCode(), ]; break; + case 'locality': $code = $address->getLocality(); $parents = [ @@ -80,6 +81,7 @@ class Subdivision extends FieldPluginBase { $address->getAdministrativeArea(), ]; break; + case 'dependent_locality': $code = $address->getDependentLocality(); $parents = [ @@ -99,4 +101,5 @@ class Subdivision extends FieldPluginBase { return $this->sanitizeValue($value); } + } diff --git a/src/Repository/CountryRepository.php b/src/Repository/CountryRepository.php index f49fe1521718cb5bcd107f4062399bb873e9879c..cf254e5b56943550d22b699ec72a6ca29fc2ab2b 100644 --- a/src/Repository/CountryRepository.php +++ b/src/Repository/CountryRepository.php @@ -69,6 +69,7 @@ class CountryRepository extends ExternalCountryRepository implements ExternalCou * Loads the base country definitions. * * @return array + * The base country definitions. */ protected function loadBaseDefinitions() { if (!empty($this->baseDefinitions)) { diff --git a/src/ZoneListBuilder.php b/src/ZoneListBuilder.php index b90280625d0991e503228e900c460abf45ecc18d..3f5e4a8f0e5f406c72ddd17ffdb41e6a03aae3ed 100644 --- a/src/ZoneListBuilder.php +++ b/src/ZoneListBuilder.php @@ -27,4 +27,3 @@ class ZoneListBuilder extends ConfigEntityListBuilder { } } - diff --git a/tests/modules/address_test/src/EventSubscriber/AddressTestEventSubscriber.php b/tests/modules/address_test/src/EventSubscriber/AddressTestEventSubscriber.php index e704e6a583557c6447a42c77860849e366f80730..17c43010916beba52b1c6e4f99cd9a5b8941413d 100644 --- a/tests/modules/address_test/src/EventSubscriber/AddressTestEventSubscriber.php +++ b/tests/modules/address_test/src/EventSubscriber/AddressTestEventSubscriber.php @@ -21,7 +21,8 @@ class AddressTestEventSubscriber implements EventSubscriberInterface { /** * Generates a set of available countries. * - * @return array The countries. + * @return array + * The countries. */ public function getAvailableCountries() { return ['AU' => 'AU', 'BR' => 'BR', 'CA' => 'CA', 'GB' => 'GB', 'JP' => 'JP']; @@ -30,7 +31,8 @@ class AddressTestEventSubscriber implements EventSubscriberInterface { /** * Generate a set of initial values. * - * @return array Array of initial values. + * @return array + * The initial values. */ public function getInitialValues() { return [ diff --git a/tests/src/FunctionalJavascript/AddressDefaultWidgetTest.php b/tests/src/FunctionalJavascript/AddressDefaultWidgetTest.php index 916534ceef8705e4575ceea94c0db2057677bfa6..e0eb3634598dec2611d6d20e3a5ff5f62f91065e 100644 --- a/tests/src/FunctionalJavascript/AddressDefaultWidgetTest.php +++ b/tests/src/FunctionalJavascript/AddressDefaultWidgetTest.php @@ -156,7 +156,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { * - default_country widget setting. * - available_countries instance setting. */ - function testCountries() { + public function testCountries() { $field_name = $this->field->getName(); // Optional field: Country should be optional and set to default_country. $this->drupalGet($this->nodeAddUrl); @@ -259,7 +259,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { /** * Tests the initial values and available countries alter events. */ - function testEvents() { + public function testEvents() { $field_name = $this->field->getName(); // The address_test module is installed here, not in setUp(). // This way the module's events will not affect other tests. @@ -268,13 +268,13 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { $this->container = $this->kernel->rebuildContainer(); // Get available countries and initial values from module's event subscriber. $subscriber = \Drupal::service('address_test.event_subscriber'); - $availableCountries = array_keys($subscriber->getAvailableCountries()); - $initialValues = $subscriber->getInitialValues(); + $available_countries = array_keys($subscriber->getAvailableCountries()); + $initial_values = $subscriber->getInitialValues(); // Access the content add form and test the list of countries. $this->drupalGet($this->nodeAddUrl); - $this->assertOptions($field_name . '[0][address][country_code]', $availableCountries, 'Available countries set in the event subscriber are present in the widget.'); + $this->assertOptions($field_name . '[0][address][country_code]', $available_countries, 'Available countries set in the event subscriber are present in the widget.'); // Test the values of the fields. - foreach ($initialValues as $key => $value) { + foreach ($initial_values as $key => $value) { if ($value) { $name = $field_name . '[0][address][' . $key . ']'; $this->assertSession()->fieldValueEquals($name, $value); @@ -303,7 +303,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { /** * Tests expected and disabled fields. */ - function testFields() { + public function testFields() { $field_name = $this->field->getName(); // Keys are field names from the field instance. // Values are corresponding field names from add article form. @@ -379,7 +379,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { /** * Tests the presence of subdivision dropdowns where expected. */ - function testSubdivisions() { + public function testSubdivisions() { $field_name = $this->field->getName(); // Using China since it has predefined subdivisions on all three levels. $country = 'CN'; @@ -410,7 +410,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { /** * Tests that changing the country clears the expected values. */ - function testClearValues() { + public function testClearValues() { $field_name = $this->field->getName(); // Create an article with all fields filled. $this->drupalGet($this->nodeAddUrl); @@ -469,7 +469,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { * variables in the message text, not t(). If left blank, a default message * will be displayed. */ - protected function assertOptions($id, $options, $message = '') { + protected function assertOptions($id, array $options, $message = '') { $elements = $this->xpath('//select[@name="' . $id . '"]/option'); $found_options = []; foreach ($elements as $element) { @@ -509,7 +509,7 @@ class AddressDefaultWidgetTest extends JavascriptTestBase { * The field values. * @param array $expected_values * The expected values. - * @param $message + * @param string $message * (optional) A message to display with the assertion. Do not translate * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed * variables in the message text, not t(). If left blank, a default message diff --git a/tests/src/FunctionalJavascript/ZoneTest.php b/tests/src/FunctionalJavascript/ZoneTest.php index 5ccb48a197bec19ddbc6c1d3515fbe94a3380e23..9715b0ecdb1612acef1a2f7bd466fa3798860a2a 100644 --- a/tests/src/FunctionalJavascript/ZoneTest.php +++ b/tests/src/FunctionalJavascript/ZoneTest.php @@ -56,7 +56,7 @@ class ZoneTest extends JavascriptTestBase { /** * Tests creating a zone via UI. */ - function testCreateZone() { + public function testCreateZone() { $this->drupalGet('admin/config/regional/zones/add'); $session = $this->getSession(); @@ -145,7 +145,7 @@ class ZoneTest extends JavascriptTestBase { /** * Tests editing a zone via UI. */ - function testEditZone() { + public function testEditZone() { $zone = $this->createZone([ 'id' => strtolower($this->randomMachineName(6)), 'name' => $this->randomMachineName(), @@ -166,7 +166,7 @@ class ZoneTest extends JavascriptTestBase { /** * Tests deleting a zone via UI. */ - function testDeleteZone() { + public function testDeleteZone() { $zone = $this->createZone([ 'id' => strtolower($this->randomMachineName(6)), 'name' => $this->randomMachineName(), @@ -201,7 +201,7 @@ class ZoneTest extends JavascriptTestBase { $status = $zone->save(); $this->assertEquals($status, SAVED_NEW, new FormattableMarkup('Created %label entity %type.', [ '%label' => $zone->getEntityType()->getLabel(), - '%type' => $zone->id() + '%type' => $zone->id(), ])); // The newly saved entity isn't identical to a loaded one, and would fail // comparisons. diff --git a/tests/src/Kernel/Formatter/PlainFormatterTest.php b/tests/src/Kernel/Formatter/PlainFormatterTest.php index 69f191200b3c70969d6d38b9d947f0265052b822..f1ea5dbc249064005339751fd0b7eeebd2cf7beb 100644 --- a/tests/src/Kernel/Formatter/PlainFormatterTest.php +++ b/tests/src/Kernel/Formatter/PlainFormatterTest.php @@ -28,7 +28,7 @@ class PlainFormatterTest extends KernelTestBase { 'text', 'entity_test', 'user', - 'address' + 'address', ]; /**