Commit aa0456a4 authored by git's avatar git Committed by bojanz

Issue #2819545 by Arez, deepal_zyxware, bojanz: Fix Coding Standard Issues.

parent fb2ceabf
......@@ -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' => [],
],
]
],
];
}
......
<?xml version="1.0"?>
<ruleset name="Commerce coding standards">
<description>Drupal 8 coding standards</description>
<exclude-pattern>*/.git/*</exclude-pattern>
<exclude-pattern>*/config/*</exclude-pattern>
<exclude-pattern>*/css/*</exclude-pattern>
<exclude-pattern>*/js/*</exclude-pattern>
<exclude-pattern>*/icons/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<rule ref="Drupal"/>
<!-- The following rules are intentionally disabled. -->
<rule ref="Drupal.Commenting.ClassComment.Missing">
<severity>0</severity>
</rule>
<rule ref="Drupal.Files.LineLength.TooLong">
<severity>0</severity>
</rule>
<rule ref="Drupal.Array.Array.LongLineDeclaration">
<severity>0</severity>
</rule>
<rule ref="Drupal.Commenting.VariableComment.VarOrder">
<severity>0</severity>
</rule>
<!-- Complains about '#element_validate callback:' -->
<rule ref="Drupal.Commenting.DocComment.ShortNotCapital">
<severity>0</severity>
</rule>
<!-- Complains a lot about tests which don't need short descriptions. -->
<rule ref="Drupal.Commenting.DocComment.MissingShort">
<severity>0</severity>
</rule>
<rule ref="Drupal.Commenting.DocComment.ShortSingleLine">
<severity>0</severity>
</rule>
<!-- Complains about annotation classes. -->
<rule ref="Drupal.NamingConventions.ValidVariableName.LowerCamelName">
<severity>0</severity>
</rule>
</ruleset>
......@@ -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;
}
......@@ -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;
}
}
......@@ -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);
......
......@@ -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.
......
......@@ -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();
......
......@@ -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';
}
......
......@@ -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;
/**
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
}
}
......
......@@ -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;
......
......@@ -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();
......
......@@ -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;
}
......
......@@ -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);
}
}
......@@ -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)) {
......
......@@ -27,4 +27,3 @@ class ZoneListBuilder extends ConfigEntityListBuilder {
}
}
......@@ -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 [
......
......@@ -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
......
......@@ -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.
......
......@@ -28,7 +28,7 @@ class PlainFormatterTest extends KernelTestBase {
'text',
'entity_test',
'user',
'address'
'address',
];
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment