Problem/Motivation

The following phpcs issues were reported on executing the command:
vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml /path/to/module

Reported Issues:

FILE: tests/src/Functional/DateTimeDayFieldTest.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
 9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
   |       |     Drupal\date_time_day\Plugin\Field\FieldType\DateTimeDayItem.
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

FILE: src/DateDayComputed.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
 10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\TypedData\TypedData.
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

FILE: src/DateTimeDayComputed.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
 8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
   |       |     Drupal\Core\Datetime\DrupalDateTime.
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

FILE: src/Plugin/Field/FieldWidget/DateTimeDayWidgetBase.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
 12 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
    |       |     Drupal\date_time_day\Plugin\Field\FieldType\DateTimeDayItem.
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

FILE: src/Plugin/Field/FieldFormatter/DateTimeDayDefaultFormatter.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
 9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is
   |       |     Drupal\date_time_day\DateTimeDayTrait.
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Proposed resolution

Run following command to fix the reported issues:

 vendor/bin/phpcbf --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml /path/to/module

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 3403330-Fix-phpcs Comparecompare

Comments

Keshav Patel created an issue. See original summary.

keshav patel’s picture

Status: Active » Needs review
StatusFileSize
new3.73 KB

The provided patch file "fix_coding_standards-3403330-2.patch" fixes the phpcs reported issues.

nikolay shapovalov’s picture

Title: Fix PHPCS Reported Issues » Fix the issues reported by phpcs
Status: Needs review » Reviewed & tested by the community

Thanks, looks good.
Patch applied, all issues fixed.

Dear maintainer can you please release a dev version from the development branch 2.0.x?

andriy khomych’s picture

Hey Nikolay, sure.

nikolay shapovalov’s picture

Status: Reviewed & tested by the community » Needs work

Looks like command I used, doesn't use phpcs.dist.xml provided by module.
I used:

phpcs -s modules/custom/date_time_day/ --report-full --report-summary --standard=modules/custom/date_time_day/phpcs.xml.dist 

And have some more issues to fix:

FILE: /var/www/html/modules/custom/date_time_day/tests/src/Functional/DateTimeDayFieldTest.php
----------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
----------------------------------------------
 28 | ERROR | [ ] @var annotation of property \Drupal\Tests\date_time_day\Functional\DateTimeDayFieldTest::$modules does not specify type hint for its items.
    |       |     (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification)
 30 | ERROR | [x] Property \Drupal\Tests\date_time_day\Functional\DateTimeDayFieldTest::$modules does not have native type hint for its value but it should be possible to add it based on @var annotation "array".
    |       |     (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
 37 | ERROR | [x] Property \Drupal\Tests\date_time_day\Functional\DateTimeDayFieldTest::$timezones does not have native type hint for its value but it should be possible to add it based on @var annotation "string[]".
    |       |     (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
 45 | ERROR | [ ] @var annotation of property \Drupal\Tests\date_time_day\Functional\DateTimeDayFieldTest::$defaultSettings does not specify type hint for its items.
    |       |     (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification)
 47 | ERROR | [x] Property \Drupal\Tests\date_time_day\Functional\DateTimeDayFieldTest::$defaultSettings does not have native type hint for its value but it should be possible to add it based on @var annotation "array".
    |       |     (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
----------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------


FILE: /var/www/html/modules/custom/date_time_day/tests/src/Kernel/DateTimeDayItemTest.php
----------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------
 27 | ERROR | [x] Property \Drupal\Tests\date_time_day\Kernel\DateTimeDayItemTest::$fieldStorage does not have native type hint for its value but it should be possible to add it based on @var annotation
    |       |     "\Drupal\field\Entity\FieldStorageConfig". (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
 34 | ERROR | [x] Property \Drupal\Tests\date_time_day\Kernel\DateTimeDayItemTest::$field does not have native type hint for its value but it should be possible to add it based on @var annotation
    |       |     "\Drupal\field\Entity\FieldConfig". (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
----------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------


FILE: /var/www/html/modules/custom/date_time_day/tests/src/Kernel/SeparatorsTranslationTest.php
----------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------
 29 | ERROR | [x] Property \Drupal\Tests\date_time_day\Kernel\SeparatorsTranslationTest::$fieldStorage does not have native type hint for its value but it should be possible to add it based on @var annotation
    |       |     "\Drupal\field\Entity\FieldStorageConfig". (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
 36 | ERROR | [x] Property \Drupal\Tests\date_time_day\Kernel\SeparatorsTranslationTest::$field does not have native type hint for its value but it should be possible to add it based on @var annotation
    |       |     "\Drupal\field\Entity\FieldConfig". (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
----------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------


FILE: /var/www/html/modules/custom/date_time_day/src/Plugin/Field/FieldWidget/DateTimeDayWidgetBase.php
----------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------
 145 | ERROR | @param annotation of method \Drupal\date_time_day\Plugin\Field\FieldWidget\DateTimeDayWidgetBase::validateStartEnd() does not specify type hint for items of its traversable parameter $element.
     |       | (SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification)
 150 | ERROR | @param annotation of method \Drupal\date_time_day\Plugin\Field\FieldWidget\DateTimeDayWidgetBase::validateStartEnd() does not specify type hint for items of its traversable parameter $complete_form.
     |       | (SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification)
----------------------------------------------


FILE: /var/www/html/modules/custom/date_time_day/src/Plugin/Field/FieldFormatter/DateTimeDayDefaultFormatter.php
----------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------
 123 | ERROR | @return annotation of method \Drupal\date_time_day\Plugin\Field\FieldFormatter\DateTimeDayDefaultFormatter::buildTimeWithAttribute() does not specify type hint for items of its traversable return value.
     |       | (SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification)
----------------------------------------------


FILE: /var/www/html/modules/custom/date_time_day/src/DateTimeDayComputed.php
--------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------
 27 | ERROR | [x] Property \Drupal\date_time_day\DateTimeDayComputed::$date does not have native type hint for its value but it should be possible to add it based on @var annotation
    |       |     "\Drupal\Core\Datetime\DrupalDateTime|null". (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
 42 | ERROR | [x] Parameter $langcode has null default value, but is not marked as nullable. (SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilityTypeMissing)
--------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------


FILE: /var/www/html/modules/custom/date_time_day/src/DateDayComputed.php
--------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------
 26 | ERROR | [x] Property \Drupal\date_time_day\DateDayComputed::$date does not have native type hint for its value but it should be possible to add it based on @var annotation
    |       |     "\Drupal\Core\Datetime\DrupalDateTime|null". (SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint)
 41 | ERROR | [x] Parameter $langcode has null default value, but is not marked as nullable. (SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilityTypeMissing)
--------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------

Time: 1.3 secs; Memory: 6MB


PHP CODE SNIFFER REPORT SUMMARY
-------------------------------------------------------------------------------------------------------------------------------
FILE                                                                                                           ERRORS  WARNINGS
-------------------------------------------------------------------------------------------------------------------------------
/var/www/html/modules/custom/date_time_day/src/DateDayComputed.php                                             2       0
/var/www/html/modules/custom/date_time_day/src/DateTimeDayComputed.php                                         2       0
/var/www/html/modules/custom/date_time_day/src/Plugin/Field/FieldFormatter/DateTimeDayDefaultFormatter.php     1       0
/var/www/html/modules/custom/date_time_day/src/Plugin/Field/FieldWidget/DateTimeDayWidgetBase.php              2       0
/var/www/html/modules/custom/date_time_day/tests/src/Functional/DateTimeDayFieldTest.php                       5       0
/var/www/html/modules/custom/date_time_day/tests/src/Kernel/DateTimeDayItemTest.php                            2       0
/var/www/html/modules/custom/date_time_day/tests/src/Kernel/SeparatorsTranslationTest.php                      2       0
-------------------------------------------------------------------------------------------------------------------------------
A TOTAL OF 16 ERRORS AND 0 WARNINGS WERE FOUND IN 7 FILES
-------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX 11 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------

Or phpcs.dist.xml needs to be updated.

Anjali Mehta made their first commit to this issue’s fork.

anjali mehta’s picture

Assigned: Unassigned » anjali mehta

andriy khomych’s picture

Fixed in the dev, however, I don't have time to check GitLab integration.
Nikolay, could you check if it works in the Gitlab integration issue https://www.drupal.org/project/date_time_day/issues/3410244?

andriy khomych’s picture

Status: Needs work » Fixed
nikolay shapovalov’s picture

Assigned: anjali mehta » Unassigned

Andriy thanks a lot for your time, I will fix few phpcs violation in the issue #3410244: Adopt GitlabCi.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.