Drupal coding standards issues

Created on 11 May 2023, over 2 years ago

Problem/Motivation

Module's code contains several Drupal Coding Standards issues. This task is created to fix them.

Steps to reproduce

Run the command:

phpcs --standard=Drupal
/web/modules/contrib/multi_image_formatter/

Proposed resolution

Fix the following coding standards issues and upload the patch or create an MR with fixes.

FILE: \modules\contrib\multi_image_formatter\src\Plugin\Field\FieldFormatter\MultiImageFormatter.php
------------------------------------------------------------------------------------------------------------------------------------
FOUND 35 ERRORS AND 6 WARNINGS AFFECTING 34 LINES
------------------------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
31 | ERROR | [ ] Missing short description in doc comment
32 | ERROR | [x] Data types in @var tags need to be fully namespaced
36 | ERROR | [ ] Missing short description in doc comment
37 | ERROR | [x] Data types in @var tags need to be fully namespaced
41 | ERROR | [ ] Missing short description in doc comment
42 | ERROR | [ ] Missing parameter comment
42 | ERROR | [ ] Missing parameter type
43 | ERROR | [ ] Missing parameter comment
43 | ERROR | [ ] Missing parameter type
44 | ERROR | [ ] Missing parameter comment
44 | ERROR | [x] Data types in @param tags need to be fully namespaced
45 | ERROR | [ ] Missing parameter comment
46 | ERROR | [ ] Missing parameter comment
46 | ERROR | [ ] Missing parameter type
47 | ERROR | [ ] Missing parameter comment
47 | ERROR | [ ] Missing parameter type
48 | ERROR | [ ] Missing parameter comment
49 | ERROR | [ ] Missing parameter comment
49 | ERROR | [x] Data types in @param tags need to be fully namespaced
50 | ERROR | [ ] Missing parameter comment
50 | ERROR | [x] Data types in @param tags need to be fully namespaced
53 | ERROR | [x] Opening brace should be on the same line as the declaration
63 | ERROR | [x] Opening brace should be on the same line as the declaration
81 | ERROR | [x] Opening brace should be on the same line as the declaration
83 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
84 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
85 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
86 | ERROR | [x] Array closing indentation error, expected 4 spaces but found 6
93 | ERROR | [x] Opening brace should be on the same line as the declaration
114 | WARNING | [x] A comma should follow the last multiline array item. Found: )
120 | WARNING | [x] A comma should follow the last multiline array item. Found: )
130 | ERROR | [x] Opening brace should be on the same line as the declaration
139 | ERROR | [x] Inline control structures are not allowed
157 | ERROR | [x] Opening brace should be on the same line as the declaration
169 | WARNING | [x] A comma should follow the last multiline array item. Found: 'container'
183 | WARNING | [x] A comma should follow the last multiline array item. Found: 'container'
193 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
207 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
213 | ERROR | [x] Expected 1 blank line after function; 0 found
214 | ERROR | [x] The closing brace for the class must have an empty line before it
----------------------------------------------------------------------------------------------------------

FILE: \modules\contrib\multi_image_formatter\src\Routing\RouteSubscriber.php
----------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
12 | ERROR | [x] Missing class doc comment
45 | ERROR | [x] Opening brace should be on the same line as the declaration
54 | ERROR | [x] Doc comment short description must start with a capital letter
54 | ERROR | [x] Doc comment short description must end with a full stop
67 | ERROR | [x] Concat operator must be surrounded by a single space
68 | ERROR | [x] Array closing indentation error, expected 8 spaces but found 6
76 | ERROR | [x] Expected 1 blank line after function; 0 found
77 | ERROR | [x] The closing brace for the class must have an empty line before it
----------------------------------------------------------------------------------------------------------

Remaining tasks

User interface changes

API changes

Data model changes

šŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India Shanu Chouhan

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

Merge Requests

Comments & Activities

  • Issue created by @Shanu Chouhan
  • Issue was unassigned.
  • Status changed to Needs review over 2 years ago
  • šŸ‡®šŸ‡³India Shanu Chouhan

    I have Created a patch to fix this issue.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡³India ashutosh ahirwal India

    Hi, Provided patch in #2 is not getting apply and throwing error.
    Moving to need work.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡³India pray_12

    Hi ,
    Applied MR1 found few more errors and warnings that need to be resolved.

    FILE: .../multi_image_formatter/src/Controller/AssetFormatController.php
    ----------------------------------------------------------------------------
    FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
    ----------------------------------------------------------------------------
     29 | WARNING | [ ] Line exceeds 80 characters; contains 92 characters
     60 | WARNING | [x] A comma should follow the last multiline array item.
        |         |     Found: )
     76 | ERROR   | [x] Additional blank lines found at end of doc comment
     79 | WARNING | [ ] MediaType::load calls should be avoided in classes, use
        |         |     dependency injection instead
    ----------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------
    
    
    FILE: ../multi_image_formatter/src/Routing/RouteSubscriber.php
    ----------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    ----------------------------------------------------------------------------
     32 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
     78 | ERROR   | [x] Concat operator must be surrounded by a single space
    ----------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------
    
    
    FILE: ...mage_formatter/src/Plugin/Field/FieldFormatter/MultiImageFormatter.php
    ----------------------------------------------------------------------------
    FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
    ----------------------------------------------------------------------------
      46 | WARNING | [ ] Line exceeds 80 characters; contains 106 characters
     221 | ERROR   | [x] Expected 1 blank line after function; 0 found
     222 | ERROR   | [x] The closing brace for the class must have an empty
         |         |     line before it
    ----------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------
    
    
    FILE: .../multi_image_formatter/multi_image_formatter.module
    ----------------------------------------------------------------------------
    FOUND 2 ERRORS AND 4 WARNINGS AFFECTING 6 LINES
    ----------------------------------------------------------------------------
     14 | ERROR   | [x] Use statements should be sorted alphabetically. The
        |         |     first wrong one is Drupal\media\Entity\MediaType.
     24 | WARNING | [x] A comma should follow the last multiline array item.
        |         |     Found: ]
     25 | WARNING | [x] A comma should follow the last multiline array item.
        |         |     Found: ]
     53 | WARNING | [x] A comma should follow the last multiline array item.
        |         |     Found: FALSE
     58 | WARNING | [x] A comma should follow the last multiline array item.
        |         |     Found: FALSE
     89 | ERROR   | [x] Namespaced classes/interfaces/traits should be
        |         |     referenced with use statements
    ----------------------------------------------------------------------------
    PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------
    
  • šŸ‡®šŸ‡³India pray_12

    Hi,
    fixed few errors and warnings.
    Remaining errors that need to be addressed are

    FILE: .../multi_image_formatter/src/Controller/AssetFormatController.php
    ----------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ----------------------------------------------------------------------------
     29 | WARNING | Line exceeds 80 characters; contains 92 characters
     78 | WARNING | MediaType::load calls should be avoided in classes, use
        |         | dependency injection instead
    ----------------------------------------------------------------------------
    
    
    FILE: ...multi_image_formatter/src/Routing/RouteSubscriber.php
    ----------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------
     32 | WARNING | Line exceeds 80 characters; contains 83 characters
    ----------------------------------------------------------------------------
    
    
    FILE: ...mage_formatter/src/Plugin/Field/FieldFormatter/MultiImageFormatter.php
    ----------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------
     46 | WARNING | Line exceeds 80 characters; contains 106 characters
    ----------------------------------------------------------------------------
    
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi

    I applied MR !1 and I confirmed that it fixes most of the PHPCS issues of hte module, however there are PHPCS issues regarding line exceeds 80 characters, hence I will retain the status to needs review so that others can review if these remaining PHPCS issues should be fixed or not.

    āžœ  multi_image_formatter git:(1.0.x) curl https://git.drupalcode.org/project/multi_image_formatter/-/merge_requests/1.diff | patch -p1                                      
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 24368    0 24368    0     0  27217      0 --:--:-- --:--:-- --:--:-- 27472
    patching file README.md
    patching file 'config/install/core.entity_form_mode.media.asset_edit.yml'
    patching file 'config/install/core.entity_view_mode.media.asset_format.yml'
    patching file multi_image_formatter.info.yml
    patching file multi_image_formatter.module
    patching file 'src/Controller/AssetFormatController.php'
    patching file 'src/Plugin/Field/FieldFormatter/MultiImageFormatter.php'
    patching file 'src/Routing/RouteSubscriber.php'
    āžœ  multi_image_formatter git:(1.0.x) āœ— ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml multi_image_formatter
    
    FILE: /Users/clarksubing-subing/Projects/d9/d9-local/web/modules/contrib/multi_image_formatter/src/Plugin/Field/FieldFormatter/MultiImageFormatter.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
     46 | WARNING | Line exceeds 80 characters; contains 106 characters
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/clarksubing-subing/Projects/d9/d9-local/web/modules/contrib/multi_image_formatter/src/Controller/AssetFormatController.php
    ---------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------------------------------------
     11 | WARNING | [x] Unused use statement
     38 | WARNING | [ ] Line exceeds 80 characters; contains 92 characters
    ---------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/clarksubing-subing/Projects/d9/d9-local/web/modules/contrib/multi_image_formatter/src/Routing/RouteSubscriber.php
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------
     32 | WARNING | Line exceeds 80 characters; contains 83 characters
    ------------------------------------------------------------------------------------------------------------------------------
    
    Time: 350ms; Memory: 10MB
    
    āžœ  contrib git:(master) āœ— 
    
    
  • Pipeline finished with Success
    over 1 year ago
    Total: 138s
    #120330
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    GitLab CI shows the following errors/warnings.

    FILE: ...dules/custom/multi_image_formatter-3359633/src/Routing/RouteSubscriber.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     32 | WARNING | Line exceeds 80 characters; contains 83 characters
        |         | (Drupal.Files.LineLength.TooLong)
    --------------------------------------------------------------------------------
    FILE: ..._formatter-3359633/src/Plugin/Field/FieldFormatter/MultiImageFormatter.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     46 | WARNING | Line exceeds 80 characters; contains 106 characters
        |         | (Drupal.Files.LineLength.TooLong)
    --------------------------------------------------------------------------------
    FILE: ...tom/multi_image_formatter-3359633/src/Controller/AssetFormatController.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     11 | WARNING | [x] Unused use statement
        |         |     (Drupal.Classes.UnusedUseStatement.UnusedUse)
     38 | WARNING | [ ] Line exceeds 80 characters; contains 92 characters
        |         |     (Drupal.Files.LineLength.TooLong)
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    Time: 171ms; Memory: 6MB
    

     
     

  • Pipeline finished with Success
    over 1 year ago
    Total: 139s
    #120333
  • šŸ‡®šŸ‡³India Yashaswi18

    On running the command "phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css", found no phpcs errors or warnings remaining.

  • Status changed to RTBC over 1 year ago
Production build 0.71.5 2024