Fixes for Drupal coding standards

Created on 23 May 2017, about 7 years ago
Updated 24 May 2024, about 1 month ago

We have to convert the module to short array syntax, plus other fixes

$ ddev phpcs
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   497  100   497    0     0   2460      0 --:--:-- --:--:-- --:--:--  2460

FILE: /var/www/html/web/modules/custom/readonlymode/readonlymode.module
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
  9 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph (Drupal.Commenting.DocComment.ShortSingleLine)
 19 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Routing\RouteMatchInterface.
    |       |     (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/custom/readonlymode/tests/src/Functional/ReadonlymodeTest.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------------------------------
 13 | ERROR | Class name doesn't match filename; expected "class ReadonlymodeTest" (Drupal.Classes.ClassFileName.NoMatch)
 22 | ERROR | Missing member variable doc comment (Drupal.Commenting.VariableComment.Missing)
--------------------------------------------------------------------------------------------------------------------------

Time: 138ms; Memory: 6MB


PHP CODE SNIFFER REPORT SUMMARY
------------------------------------------------------------------------------------------------------------
FILE                                                                                        ERRORS  WARNINGS
------------------------------------------------------------------------------------------------------------
/var/www/html/web/modules/custom/readonlymode/readonlymode.module                           2       0
/var/www/html/web/modules/custom/readonlymode/tests/src/Functional/ReadonlymodeTest.php     2       0
------------------------------------------------------------------------------------------------------------
A TOTAL OF 4 ERRORS AND 0 WARNINGS WERE FOUND IN 2 FILES
------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX 1 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------


PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
--------------------------------------------------------------------------------------------
    SOURCE                                                                             COUNT
--------------------------------------------------------------------------------------------
[ ] Drupal.Classes.ClassFileName.NoMatch                                               1
[ ] Drupal.Commenting.DocComment.ShortSingleLine                                       1
[ ] Drupal.Commenting.VariableComment.Missing                                          1
[x] SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses  1
--------------------------------------------------------------------------------------------
A TOTAL OF 4 SNIFF VIOLATIONS WERE FOUND IN 4 SOURCES
--------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SOURCES AUTOMATICALLY (1 VIOLATIONS IN TOTAL)
--------------------------------------------------------------------------------------------
šŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India Pavan B S

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review 4 months ago
  • Status changed to Needs work 4 months ago
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi

    I applied the MR !6 and there are PHPCS errors and warning that my terminal flagged

    āžœ  readonlymode git:(3abe435) curl https://git.drupalcode.org/project/readonlymode/-/merge_requests/6.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 18417    0 18417    0     0  36829      0 --:--:-- --:--:-- --:--:-- 37432
    patching file readonlymode.module
    patching file 'src/Plugin/Block/ReadonlymodeBlock.php'
    patching file 'tests/fixtures/drupal7.php'
    patching file 'tests/src/Functional/ReadonlymodeTest.php'
    āžœ  readonlymode git:(3abe435) āœ— ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml readonlymode 
    
    FILE: ...web/modules/contrib/readonlymode/tests/src/Functional/ReadonlymodeTest.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     13 | ERROR | Class name doesn't match filename; expected "class
        |       | ReadonlymodeTest"
    --------------------------------------------------------------------------------
    
    
    FILE: ...al/web/modules/contrib/readonlymode/src/Plugin/Block/ReadonlymodeBlock.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
    --------------------------------------------------------------------------------
     15 | ERROR   | Class name doesn't match filename; expected "class
        |         | ReadonlymodeBlock"
     22 | WARNING | \Drupal calls should be avoided in classes, use dependency
        |         | injection instead
     24 | WARNING | \Drupal calls should be avoided in classes, use dependency
        |         | injection instead
    --------------------------------------------------------------------------------
    
    Time: 339ms; Memory: 12MB
    
    āžœ  contrib git:(master) āœ— 
    
  • Status changed to Needs review 4 months ago
  • That's because the case of the files was changed, but changing the case of files doesn't work in certain operating systems (during patching). The code itself is correct. Look at the following line, the file is not ReadonlymodeBlock.php anymore; it's ReadOnlyModeBlock.php.

    https://git.drupalcode.org/project/readonlymode/-/merge_requests/6/diffs...

  • Status changed to Needs work 4 months ago
  • I will update the uses of \Drupal to injection.

  • Status changed to Needs review 4 months ago
  • Status changed to Needs work about 1 month ago
  • Hi @solideogloria,

    Applied the plain diff, and found one error

    FILE: ...web/modules/contrib/readonlymode/tests/src/Functional/ReadonlymodeTest.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     13 | ERROR | Class name doesn't match filename; expected "class
        |       | ReadonlymodeTest"
    --------------------------------------------------------------------------------
    
    Time: 256ms; Memory: 12MB

    Kindly work on it, please.
    Thank you.

  • Status changed to Needs review about 1 month ago
  • The file name was changed in the patch, so they actually do match. However, you cannot simply apply the patch with Composer, because Windows computers won't rename the file if the letters are the same, even if the case is different.

    See my previous comments in #9. šŸ“Œ Fixes for Drupal coding standards Needs review

Production build 0.69.0 2024