Fix the issues reported by PHP_CodeSniffer

Created on 24 September 2024, 4 months ago

Problem/Motivation

FILE: city_weather_field\city_weather_field.info.yml
-------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------
1 | WARNING | Remove "project" from the info file, it will be added by drupal.org packaging automatically
1 | WARNING | Remove "datestamp" from the info file, it will be added by drupal.org packaging automatically
1 | WARNING | Remove "version" from the info file, it will be added by drupal.org packaging automatically
-------------------------------------------------------------------------------------------------------------

FILE: city_weather_field\city_weather_field.module
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
53 | ERROR | Description for the @return value is missing
--------------------------------------------------------------------------------

FILE: city_weather_field\README.md
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
42 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: city_weather_field\src\Form\WeatherSettingsForm.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
10 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------

FILE: city_weather_field\src\Plugin\Field\FieldFormatter\WeatherFieldFormatter.php
------------------------------------------------------------------------------------------------------------------------------------
FOUND 21 ERRORS AFFECTING 12 LINES
------------------------------------------------------------------------------------------------------------------------------------
10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\city_weather_field\WeatherService.
69 | ERROR | [ ] Parameter $weather_service is not described in comment
69 | ERROR | [ ] Parameter $config_factory is not described in comment
72 | ERROR | [ ] Missing parameter comment
72 | ERROR | [ ] Missing parameter type
73 | ERROR | [ ] Missing parameter comment
73 | ERROR | [ ] Missing parameter type
74 | ERROR | [ ] Missing parameter comment
74 | ERROR | [x] Data types in @param tags need to be fully namespaced
75 | ERROR | [ ] Missing parameter comment
76 | ERROR | [ ] Missing parameter comment
76 | ERROR | [ ] Missing parameter type
77 | ERROR | [ ] Missing parameter comment
77 | ERROR | [ ] Missing parameter type
78 | ERROR | [ ] Missing parameter comment
79 | ERROR | [ ] Missing parameter comment
79 | ERROR | [ ] Doc comment for parameter $weatherService does not match actual variable name $config_factory
79 | ERROR | [x] Data types in @param tags need to be fully namespaced
101 | ERROR | [x] Expected 1 space after IF keyword; 0 found
101 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
119 | ERROR | [x] Expected 1 newline at end of file; 2 found
------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------

FILE: city_weather_field\src\Plugin\Field\FieldType\WeatherFieldType.php
------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------
3 | ERROR | [x] There must be one blank line after the namespace declaration
59 | ERROR | [x] Expected 1 newline at end of file; 2 found
------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------

FILE: city_weather_field\src\Plugin\Field\FieldWidget\WeatherFieldWidget.php
----------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------------------------------------------
28 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
29 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
30 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
31 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
32 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
33 | ERROR | [x] Array closing indentation error, expected 4 spaces but found 6
35 | ERROR | [x] Expected 1 blank line after function; 0 found
36 | ERROR | [x] Expected 1 newline at end of file; 2 found
36 | ERROR | [x] The closing brace for the class must have an empty line before it
----------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------

FILE: city_weather_field\src\WeatherService.php
---------------------------------------------------------------------------------------------------------------------
FOUND 15 ERRORS AND 1 WARNING AFFECTING 15 LINES
---------------------------------------------------------------------------------------------------------------------
12 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
17 | ERROR | [x] There must be exactly one blank line before the tags in a doc comment
31 | ERROR | [x] Expected 1 space before opening brace; found 0
38 | ERROR | [x] Expected 1 space before opening brace; found 0
47 | ERROR | [ ] Missing parameter comment
48 | ERROR | [ ] Missing parameter comment
50 | ERROR | [ ] Description for the @return value is missing
52 | ERROR | [x] Expected 1 space before opening brace; found 0
58 | ERROR | [x] Expected newline after closing brace
59 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
59 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
65 | ERROR | [x] Use null coalesce operator instead of ternary operator.
67 | ERROR | [x] Use null coalesce operator instead of ternary operator.
68 | ERROR | [x] Use null coalesce operator instead of ternary operator.
69 | ERROR | [x] Use null coalesce operator instead of ternary operator.
70 | ERROR | [x] Use null coalesce operator instead of ternary operator.
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Run phpcs command to get the drupal coding standard issues.

Proposed resolution

Many of the issues can be fixed by running the phpcbf command. For the remaining ones, we will need to manually address and then commit these changes before pushing them.

šŸ“Œ Task
Status

Needs work

Version

3.0

Component

Code

Created by

šŸ‡ŗšŸ‡øUnited States sunil jolapara 3265 Summitrun Drive, Independence, KY, 41051

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @sunil jolapara
  • šŸ‡ŗšŸ‡øUnited States sunil jolapara 3265 Summitrun Drive, Independence, KY, 41051

    sunil jolapara ā†’ changed the visibility of the branch 3476322-fix-the-phpcodesniffer-issues to hidden.

  • šŸ‡ŗšŸ‡øUnited States sunil jolapara 3265 Summitrun Drive, Independence, KY, 41051
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    The issue summary for PHP_CodeSniffer issues should always show the report given from PHP_CodeSniffer and the arguments passed to phpcs.

    Furthermore, since GitLab CI is now enabled for all the projects, GitLab CI should be used to get PHP_CodeSniffer errors/warnings.

  • šŸ‡µšŸ‡­Philippines cleavinjosh
  • šŸ‡µšŸ‡­Philippines cleavinjosh
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    MR!2 will be merged to 8.x-1.x

  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @sunil jolapara,

    Thank you for providing an MR. I applied MR!2 on 3.0.x, it was not applied smoothly.

    āžœ  city_weather_field git:(3.0.x) curl https://git.drupalcode.org/project/city_weather_field/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 10664    0 10664    0     0  26254      0 --:--:-- --:--:-- --:--:-- 26266
    patching file README.md
    patching file city_weather_field.info.yml
    Reversed (or previously applied) patch detected!  Assume -R? [n] -R
    Apply anyway? [n] n
    Skipping patch.
    1 out of 1 hunk ignored -- saving rejects to file city_weather_field.info.yml.rej
    patching file city_weather_field.module
    Hunk #1 FAILED at 50.
    1 out of 1 hunk FAILED -- saving rejects to file city_weather_field.module.rej
    patching file src/Form/WeatherSettingsForm.php
    patching file src/Plugin/Field/FieldFormatter/WeatherFieldFormatter.php
    patching file src/Plugin/Field/FieldType/WeatherFieldType.php
    patching file src/Plugin/Field/FieldWidget/WeatherFieldWidget.php
    patching file src/WeatherService.php
    Hunk #2 FAILED at 32.
    1 out of 2 hunks FAILED -- saving rejects to file src/WeatherService.php.rej
    āžœ  city_weather_field git:(3.0.x) āœ—

    I applied it to 8.x-1.x, it was applied smoothly and fixed most of the phpcs issues.
    This is the remaining issue after I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml:

    āžœ  city_weather_field git:(8.x-1.x) āœ— curl https://git.drupalcode.org/project/city_weather_field/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 10664    0 10664    0     0  26001      0 --:--:-- --:--:-- --:--:-- 26073
    patching file README.md
    patching file city_weather_field.info.yml
    patching file city_weather_field.module
    patching file src/Form/WeatherSettingsForm.php
    patching file src/Plugin/Field/FieldFormatter/WeatherFieldFormatter.php
    patching file src/Plugin/Field/FieldType/WeatherFieldType.php
    patching file src/Plugin/Field/FieldWidget/WeatherFieldWidget.php
    patching file src/WeatherService.php
    āžœ  city_weather_field git:(8.x-1.x) āœ— ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml city_weather_field
    
    FILE: /Users/interns/Demo-site/drupal_11_test/install-dir/drupal_11_test_site/web/modules/contrib/city_weather_field/src/WeatherService.php
    -------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------------
     70 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -------------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 163ms; Memory: 10MB
    
    āžœ  contrib git:(main) āœ—
  • Pipeline finished with Failed
    2 months ago
    Total: 108s
    #338495
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    cleavinjosh ā†’ changed the visibility of the branch 3476322-phpcs-issues to hidden.

  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi,

    Please check and advise on MR!2.

    Thank you.

  • Pipeline finished with Failed
    2 months ago
    Total: 108s
    #338836
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    The issue summary must still be updated: Neither in the 8.x-1.x branch, nor in the 3.0.x branch the .yml file contains a project, datetime, or version line.

  • šŸ‡µšŸ‡­Philippines cleavinjosh
  • šŸ‡µšŸ‡­Philippines cleavinjosh
  • Issue was unassigned.
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    Only a branch is supported. The unsupported branch is no longer changed.
    The list of the errors/warnings to fix should be given by GitLab CI.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 107s
    #367594
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi,

    There might have been some composer dependency resolution issues.

    I am not sure how to proceed.

    Please check and advise. Thank you.

  • Pipeline finished with Success
    about 1 month ago
    Total: 267s
    #368371
  • Pipeline finished with Canceled
    about 1 month ago
    Total: 74s
    #368374
  • Pipeline finished with Success
    about 1 month ago
    Total: 144s
    #368375
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    about 1 month ago
    Total: 322s
    #370673
  • Pipeline finished with Success
    about 1 month ago
    Total: 148s
    #370681
  • Pipeline finished with Success
    about 1 month ago
    Total: 150s
    #370689
  • Pipeline finished with Success
    about 1 month ago
    Total: 159s
    #370693
  • Pipeline finished with Success
    about 1 month ago
    Total: 140s
    #370719
  • Pipeline finished with Success
    about 1 month ago
    Total: 112s
    #370725
  • Pipeline finished with Success
    about 1 month ago
    Total: 208s
    #370728
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi,

    Please review, check, and advise on MR!4. Thank you.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    avpaderno ā†’ changed the visibility of the branch 3476322-gitlab-ci-reports to hidden.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    MR!4 was created just to get the list of the errors/warnings to fix.

  • šŸ‡µšŸ‡­Philippines cleavinjosh

    cleavinjosh ā†’ changed the visibility of the branch 3476322-fix-the-phpcodesniffer-issues to hidden.

  • Merge request !5Resolve #3476322 "Fix phpcs issues" ā†’ (Open) created by cleavinjosh
  • Pipeline finished with Failed
    about 1 month ago
    Total: 113s
    #372306
  • Pipeline finished with Success
    about 1 month ago
    Total: 143s
    #372309
  • Pipeline finished with Success
    about 1 month ago
    Total: 156s
    #372322
  • Pipeline finished with Success
    about 1 month ago
    Total: 153s
    #372328
  • Pipeline finished with Success
    about 1 month ago
    Total: 141s
    #372331
  • Pipeline finished with Success
    about 1 month ago
    Total: 166s
    #372339
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi,

    Please review, check, and advise on MR!5. Thank you.

Production build 0.71.5 2024