Fix the issues reported by phpcs

Created on 22 November 2023, about 1 year ago
Updated 4 January 2024, 11 months ago

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

๐Ÿ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia keshav patel

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Comments & Activities

  • Issue created by @keshav patel
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia keshav patel

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

  • Status changed to RTBC 11 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia zniki.ru

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

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

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine andriy khomych

    Hey Nikolay, sure.

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia zniki.ru

    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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Anjali Mehta

    Anjali Mehta โ†’ made their first commit to this issueโ€™s fork.

  • Assigned to Anjali Mehta
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine andriy khomych

    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 ๐Ÿ“Œ Adopt GitlabCi Needs review ?

  • Status changed to Fixed 11 months ago
  • Issue was unassigned.
  • ๐Ÿ‡ท๐Ÿ‡บRussia zniki.ru

    Andriy thanks a lot for your time, I will fix few phpcs violation in the issue ๐Ÿ“Œ Adopt GitlabCi Needs review .

  • Status changed to Fixed 11 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024