Fix issues reported by PHPCS

Created on 12 February 2025, 2 months ago

Problem/Motivation

It would be great to address the below minor PHPCS issues :

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml faker/


FILE: /var/www/web/modules/contrib/faker/README.md
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 11 | WARNING | Line exceeds 80 characters; contains 87 characters
 22 | WARNING | Line exceeds 80 characters; contains 91 characters
 26 | WARNING | Line exceeds 80 characters; contains 114 characters
----------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/FakerDataSampler/CountryCodeFakerDataSampler.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------
 19 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 25 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/FakerDataSampler/RealTextWithSummaryFakerDataSampler.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------
 19 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 25 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/FakerDataSampler/EmailFakerDataSampler.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------
 20 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 26 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/FakerDataSampler/TextWithSummaryFakerDataSampler.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------
 19 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 25 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/FakerDataSampler/ImageFakerDataSampler.php
---------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
---------------------------------------------------------------------------------------------------------------------
 22 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 28 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
 67 | ERROR   | [x] list(...) is forbidden, use [...] instead.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/FakerDataSampler/CountryFakerDataSampler.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------
 19 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 25 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/DevelGenerate/FakerUserDevelGenerate.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 16 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Plugin/DevelGenerate/FakerContentDevelGenerate.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 16 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerDevelGenerateTrait.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 12 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerDataSamplerManager.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 14 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/Form/FakerProfileForm.php
---------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
---------------------------------------------------------------------------------------------
 54 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 55 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerProfileListBuilder.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 12 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerDataSamplerInterface.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------
 11 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 27 | ERROR   | [x] Parameter $field_definition has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerHelper.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 12 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerConstants.php
----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------
 7 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
----------------------------------------------------------------------------------------------------------------


FILE: /var/www/web/modules/contrib/faker/src/FakerDataSamplerBase.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 11 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------

Time: 528ms; Memory: 12MB

Steps to reproduce

Run the command,
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml faker/

Proposed resolution

Fix the phpcs issues.

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇮🇳India abhiyanshu

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

Merge Requests

Comments & Activities

  • Issue created by @abhiyanshu
  • First commit to issue fork.
  • Merge request !4#3506099 Fix phpcs → (Open) created by jonathan1055
  • Pipeline finished with Success
    2 months ago
    Total: 154s
    #422666
  • 🇬🇧United Kingdom jonathan1055

    Starting point, the pipeline phpcs summary shows

    --------------------------------------------------------------------------------
    PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
    --------------------------------------------------------------------------------
        SOURCE                                                                 COUNT
    --------------------------------------------------------------------------------
    [ ] Drupal.Commenting.ClassComment.Short                                   15
    [x] SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.Null  7
    [x] SlevomatCodingStandard.PHP.ShortList.LongListUsed                      1
    --------------------------------------------------------------------------------
    A TOTAL OF 23 SNIFF VIOLATIONS WERE FOUND IN 3 SOURCES

    Initial push on MR4 now has

    ----------------------------------------------------------------------
    SOURCE                                                           COUNT
    ----------------------------------------------------------------------
    Drupal.Commenting.ClassComment.Short                             15
    ----------------------------------------------------------------------
    A TOTAL OF 15 SNIFF VIOLATIONS WERE FOUND IN 1 SOURCE
    ----------------------------------------------------------------------
    

    I will work on this more tomorrow.

  • 🇬🇧United Kingdom jonathan1055

    The reason for the reduced number of faults compared to the output shown in the issue summary are due to two things:

    1. The DrupalPractice standard is not included by default in the gitlab pipeline phpcs job. Only the Drupal set of rules is used. If you would like the pipeline job to check against best practices, then the way to do this is to have a phpcs.xml.dist file in the project folder, and to specify both sets of standards. Here is an example
    2. The reason that the long lines in README are not reported is that .md files are not included by default. Again this can be changed by adding 'md' as an extension, see this example
  • Pipeline finished with Success
    2 months ago
    Total: 136s
    #423065
  • 🇬🇧United Kingdom jonathan1055

    As a bonus, I have corrected the spelling error (UK -> US) so that job is green now.

    I'm happy to help with setting up the phpcs.xml file if you want, depending on your views of the two points in #5

    But I will let someone else write the proper short descriptions of the classes, someone who knows about this project. Over to you ...

  • 🇧🇪Belgium baikho Antwerp, BE

    Happy for the pipeline to include the DrupalPractice standard and READMEs.

    As a bonus, I have corrected the spelling error (UK -> US) so that job is green now.

    I'm happy to help with setting up the phpcs.xml file if you want, depending on your views of the two points in #5

    Thanks for those fixes already, gladly have your help on these. I'll try and find some time to fix the descriptions.

  • Pipeline finished with Success
    2 months ago
    Total: 142s
    #425163
  • 🇬🇧United Kingdom jonathan1055

    I have added a phpcs.xml file to include all sniffs in DrupalPractice and also to check .md files. The job shows

    PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
    ----------------------------------------------------------------------
    SOURCE                                                           COUNT
    ----------------------------------------------------------------------
    Drupal.Commenting.ClassComment.Short                             15
    Drupal.Files.TxtFileLineLength.TooLong                           3
    DrupalPractice.Objects.GlobalDrupal.GlobalDrupal                 2
    ----------------------------------------------------------------------
    A TOTAL OF 20 SNIFF VIOLATIONS WERE FOUND IN 3 SOURCES
    ----------------------------------------------------------------------

    [The issue summary update is just to make it more readable, I re-ran on 3.x with --report-widht=90 and a --basepath option]

  • Pipeline finished with Success
    2 months ago
    #425172
  • 🇬🇧United Kingdom jonathan1055

    I have fixed the long lines in README.md and the rendered file looks fine.
    https://git.drupalcode.org/issue/faker-3506099/-/blob/3506099-fix-phpcs/...

  • Pipeline finished with Success
    2 months ago
    Total: 471s
    #425580
Production build 0.71.5 2024