Fix coding standards

Created on 6 February 2023, almost 2 years ago
Updated 21 August 2024, 3 months ago

Problem/Motivation

A scan of this module reveals some coding standards issues:


FILE: /var/www/html/web/modules/contrib/consumer_image_styles/consumer_image_styles.module
------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------
 54 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/consumer_image_styles/tests/src/Functional/ConsumerImageSylesFunctionalTest.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 9 LINES
-----------------------------------------------------------------------------------------------------------------------
  19 | ERROR | [ ] Missing short description in doc comment
  28 | ERROR | [ ] Missing member variable doc comment
  43 | ERROR | [ ] Missing short description in doc comment
  62 | ERROR | [ ] Missing short description in doc comment
  67 | ERROR | [ ] Missing short description in doc comment
  72 | ERROR | [ ] Missing short description in doc comment
 157 | ERROR | [x] Use null coalesce operator instead of ternary operator.
 180 | ERROR | [x] Use null coalesce operator instead of ternary operator.
 195 | ERROR | [x] Use null coalesce operator instead of ternary operator.
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/consumer_image_styles/src/ImageStylesProviderInterface.php
-------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------------------
 41 | ERROR | [ ] Expected type hint "CacheableMetadata"; found "?CacheableMetadata" for $cacheable_metadata
 51 | ERROR | [x] Return comment indentation must be 3 spaces, found 1 spaces
-------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/consumer_image_styles/src/ImageStylesProvider.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AND 4 WARNINGS AFFECTING 7 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  23 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
  70 | ERROR   | [ ] Expected type hint "StreamWrapperManagerInterface"; found "?StreamWrapperManagerInterface" for $stream_wrapper_manager
  80 | WARNING | [ ] The deprecation-version '4.0.6' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n] or
     |         |     project:n.n.n or project:n.n.n-label[n]
  80 | WARNING | [ ] The removal-version '5.0' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n] or project:n.n.n or
     |         |     project:n.n.n-label[n]
  81 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 114 | ERROR   | [ ] The trigger_error message 'Calling %s without $cacheable_metadata is deprecated in 4.0.6; it is required in 5.0.' does not match the relaxed standard format:
     |         |     %thing% is deprecated in %deprecation-version% any free text %removal-version%. %extra-info%. See %cr-link%
 140 | ERROR   | [x] Expected 1 blank line after function; 2 found
 144 | ERROR   | [ ] Doc comment short description must start with a capital letter
 144 | ERROR   | [ ] Doc comment short description must end with a full stop
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/consumer_image_styles/src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php
---------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
---------------------------------------------------------------------------------------------------------------
  30 | ERROR   | Missing short description in doc comment
  35 | ERROR   | Missing short description in doc comment
 245 | WARNING | ImageStyle::loadMultiple calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/consumer_image_styles/src/Normalizer/LinkCollectionNormalizer.php
---------------------------------------------------------------------------------------------------------
FOUND 11 ERRORS AND 1 WARNING AFFECTING 10 LINES
---------------------------------------------------------------------------------------------------------
  13 | WARNING | [x] Unused use statement
  27 | ERROR   | [ ] Missing short description in doc comment
  32 | ERROR   | [ ] Missing short description in doc comment
  37 | ERROR   | [ ] Missing short description in doc comment
  42 | ERROR   | [ ] Missing short description in doc comment
  61 | ERROR   | [ ] Parameter $imageStylesProvider is not described in comment
  68 | ERROR   | [ ] Missing parameter name
 111 | ERROR   | [ ] Missing short description in doc comment
 111 | ERROR   | [ ] Parameter $consumer is not described in comment
 112 | ERROR   | [ ] Missing parameter comment
 113 | ERROR   | [ ] Missing parameter comment
 113 | ERROR   | [ ] Missing parameter name
---------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------
šŸ“Œ Task
Status

Needs review

Version

4.0

Component

Code

Created by

šŸ‡ÆšŸ‡µJapan ptmkenny

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

Comments & Activities

  • Issue created by @ptmkenny
  • @ptmkenny opened merge request.
  • Status changed to Needs review almost 2 years ago
  • šŸ‡ÆšŸ‡µJapan ptmkenny

    The MR fixes all of the issues in the Issue Summary except:

    FILE: /var/www/html/web/modules/contrib/consumer_image_styles/src/ImageStylesProvider.php
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 3 WARNINGS AFFECTING 3 LINES
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      80 | WARNING | The deprecation-version '4.0.6' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n] or project:n.n.n
         |         | or project:n.n.n-label[n]
      80 | WARNING | The removal-version '5.0' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or project:n.x-n.n-label[n] or project:n.n.n or
         |         | project:n.n.n-label[n]
      81 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     114 | ERROR   | The trigger_error message 'Calling %s without $cacheable_metadata is deprecated in 4.0.6; it is required in 5.0.' does not match the relaxed standard format:
         |         | %thing% is deprecated in %deprecation-version% any free text %removal-version%. %extra-info%. See %cr-link%
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/html/web/modules/contrib/consumer_image_styles/src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php
    ---------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------
     249 | WARNING | ImageStyle::loadMultiple calls should be avoided in classes, use dependency injection instead
    ---------------------------------------------------------------------------------------------------------------
    

    I think dependency injection should be handled in a separate issue because it can break things, and I don't know how to fix the deprecation messages.

  • Status changed to Needs work 3 months ago
  • Hi @ptmkenny,

    Applied the latest changes committed on MR!13, it was applied successfully on my local, but there are still errors reported aside from dependency injection. Please see below:

    āžœ  consumer_image_styles git:(4.x) curl https://git.drupalcode.org/project/consumer_image_styles/-/merge_requests/13.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 10311    0 10311    0     0  33997      0 --:--:-- --:--:-- --:--:-- 35555
    patching file consumer_image_styles.module
    patching file src/ImageStylesProvider.php
    patching file src/ImageStylesProviderInterface.php
    patching file src/Normalizer/LinkCollectionNormalizer.php
    patching file src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php
    patching file tests/src/Functional/ConsumerImageSylesFunctionalTest.php
    āžœ  consumer_image_styles git:(4.x) āœ— ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig consumer_image_styles
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/consumer_image_styles/src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php
    --------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    --------------------------------------------------------------------------------------------------------------------------------------------------
      52 | ERROR   | [x] Multi-line function declarations must have a trailing comma after the last parameter
     249 | WARNING | [ ] ImageStyle::loadMultiple calls should be avoided in classes, use dependency injection instead
    --------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/consumer_image_styles/src/Normalizer/LinkCollectionNormalizer.php
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------------------------------------------
     8 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\consumer_image_styles\ImageStylesProviderInterface.
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/consumer_image_styles/src/ImageStylesProvider.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AND 3 WARNINGS AFFECTING 5 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
      13 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\StreamWrapper\StreamWrapperInterface.
      74 | ERROR   | [x] Multi-line function declarations must have a trailing comma after the last parameter
      80 | WARNING | [ ] The deprecation-version '4.0.6' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or
         |         |     project:n.x-n.n-label[n] or project:n.n.n or project:n.n.n-label[n]
      80 | WARNING | [ ] The removal-version '5.0' does not match the lower-case machine-name standard: drupal:n.n.n or project:n.x-n.n or
         |         |     project:n.x-n.n-label[n] or project:n.n.n or project:n.n.n-label[n]
      81 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
     114 | ERROR   | [ ] The trigger_error message 'Calling %s without $cacheable_metadata is deprecated in 4.0.6; it is required in 5.0.' does not match the
         |         |     relaxed standard format: %thing% is deprecated in %deprecation-version% any free text %removal-version%. %extra-info%. See %cr-link%
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 404ms; Memory: 12MB

    Kindly check

    Thanks,
    Jake

  • Status changed to Needs review 3 months ago
  • šŸ‡ÆšŸ‡µJapan ptmkenny

    @a.aaronjake These are the coding standards/phpcs fixes for the CI test run by the GitLab CI template. The CI template classifies DI issues as phpstan issues, not phpcs issues (this is done to prevent the issues from being fixed twice in different issues).

    The issue to add the CI template is here: šŸ“Œ Add gitlab CI Needs review

Production build 0.71.5 2024