Fixing the warnings reported by PHPCS

Created on 16 August 2023, over 1 year ago

Hi, here are the errors reported by PHPCS :

FILE: app/web/modules/custom/field_image_style/src/Plugin/Field/FieldType/ImageStyleItem.php
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 16 ERRORS AND 4 WARNINGS AFFECTING 17 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
   7 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Form\FormStateInterface.
  41 | ERROR   | [x] Short array syntax must be used to define arrays
  51 | ERROR   | [x] Short array syntax must be used to define arrays
  52 | ERROR   | [x] Short array syntax must be used to define arrays
  53 | ERROR   | [x] Short array syntax must be used to define arrays
  58 | ERROR   | [x] Short array syntax must be used to define arrays
  59 | ERROR   | [x] Short array syntax must be used to define arrays
  70 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
  93 | ERROR   | [x] Short array syntax must be used to define arrays
  95 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  97 | ERROR   | [x] Short array syntax must be used to define arrays
  97 | ERROR   | [x] Short array syntax must be used to define arrays
  97 | ERROR   | [ ] The array declaration extends to column 83 (the limit is 80). The array content should be split up over multiple lines
 108 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 119 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 153 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
 154 | WARNING | [ ] Avoid backslash escaping in translatable strings when possible, use "" quotes instead
 154 | ERROR   | [x] Short array syntax must be used to define arrays
 156 | ERROR   | [x] Expected 1 blank line after function; 2 found
 159 | ERROR   | [x] The closing brace for the class must have an empty line before it
----------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 15 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------


FILE: app/web/modules/custom/field_image_style/src/Plugin/Field/FieldFormatter/ImageStyleImageFormatter.php
--------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 18 ERRORS AND 13 WARNINGS AFFECTING 30 LINES
--------------------------------------------------------------------------------------------------------------------------------------------------------
   5 | WARNING | [x] Unused use statement
   7 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Field\FieldItemListInterface.
  29 | ERROR   | [x] Short array syntax must be used to define arrays
  38 | ERROR   | [x] Short array syntax must be used to define arrays
  40 | WARNING | [x] '@todo: find a way to get all image_style fields of the current entity bundle' should match the format '@todo Fix problem X here.'
  41 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
  44 | ERROR   | [x] Expected 1 space after FOREACH keyword; 0 found
  45 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
  50 | ERROR   | [x] Short array syntax must be used to define arrays
  51 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  54 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  57 | ERROR   | [x] Short array syntax must be used to define arrays
  58 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  59 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  61 | ERROR   | [x] Short array syntax must be used to define arrays
  62 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  65 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  76 | ERROR   | [x] Short array syntax must be used to define arrays
  80 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  80 | ERROR   | [x] Short array syntax must be used to define arrays
  83 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  86 | ERROR   | [x] Short array syntax must be used to define arrays
  87 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  88 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 103 | ERROR   | [x] Short array syntax must be used to define arrays
 124 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 126 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
 128 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
 44 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 53 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
--------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------

FILE: app/web/modules/custom/field_image_style/field_image_style.module
--------------------------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AND 1 WARNING AFFECTING 5 LINES
--------------------------------------------------------------------------------------------------------------------------------
  9 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Form\FormStateInterface.
  9 | ERROR   | [x] There must be one blank line after the last USE statement; 2 found;
 15 | ERROR   | [x] Expected 1 blank line before function; 2 found
 33 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
 44 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 53 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
--------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------
📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France bakop Lille

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

Merge Requests

Comments & Activities

  • Issue created by @bakop
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • First commit to issue fork.
  • 🇮🇳India mukhtarm

    Addressed the MR comments, please review

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    In Constructs an ImageStyleImageFormatter object. there is no namespace.

  • 🇮🇳India mukhtarm

    @apaderno Can you clarify a bit more? The namespace is included in as the first line in the class

    namespace Drupal\field_image_style\Plugin\Field\FieldFormatter;

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Constructs an ImageStyleImageFormatter object. does not contain any namespace. What the namespace for the file is does not matter.

  • Assigned to bakop
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇫🇷France bakop Lille

    There is a phpcs error on the constructor line. I did the modification.
    @apaderno why do we need to change the class name and add the namespace into it ? Actually we have "Plugin implementation of the 'image_style_formatter' formatter." with the "FieldFormatter" annotation.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    It does not matter. The construction description must be similar to the following one.

      /**
       * Constructs a \Drupal\user\AccountSettingsForm object.
       *
       * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
       *   The factory for configuration objects.
       * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
       *   The module handler.
       * @param \Drupal\user\RoleStorageInterface $role_storage
       *   The role storage.
       */
      /**
       * Constructs a \Drupal\migrate\Row object.
       *
       * @param array $values
       *   An array of values to add as properties on the object.
       * @param array $source_ids
       *   An array containing the IDs of the source using the keys as the field
       *   names.
       * @param bool $is_stub
       *   TRUE if the row being created is a stub.
       *
       * @throws \InvalidArgumentException
       *   Thrown when a source ID property does not exist.
       */
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Conflict: This file was modified in both the source and target branches. Ask someone with write access to resolve it.

  • Assigned to bakop
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇫🇷France bakop Lille

    I can't modify the line in question because it no longer respects the 80 character rule.
    I rebased the branch and removed the added class comment

  • Status changed to Needs work 8 months ago
  • Hi @bakop,

    Applied the changes you committed on MR!2, it was applied smoothly but one error still reported. Please see below:

    ➜  field_image_style git:(8.x-1.x) curl https://git.drupalcode.org/project/field_image_style/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 15536    0 15536    0     0  33434      0 --:--:-- --:--:-- --:--:-- 34070
    patching file field_image_style.module
    patching file src/Plugin/Field/FieldFormatter/ImageStyleImageFormatter.php
    patching file src/Plugin/Field/FieldType/ImageStyleItem.php
    ➜  field_image_style 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,twig field_image_style
    
    
    FILE: ...d_image_style/src/Plugin/Field/FieldFormatter/ImageStyleImageFormatter.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     12 | ERROR | [x] Use statements should be sorted alphabetically. The first
        |       |     wrong one is Drupal\Core\File\FileUrlGeneratorInterface.
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    Time: 247ms; Memory: 10MB

    Kindly check

    Thanks,
    Jake

  • Pipeline finished with Success
    8 months ago
    #255015
  • Status changed to Needs review 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Pipeline finished with Success
    8 months ago
    Total: 179s
    #255034
  • Pipeline finished with Success
    8 months ago
    Total: 129s
    #255047
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    avpaderno changed the visibility of the branch 3381506-gitlab-ci-reports to hidden.

  • Status changed to RTBC 3 months ago
  • 🇵🇭Philippines paraderojether

    Hi

    I reviewed MR!2, and confirmed it fixes the phpcs issues reported by the PHP_CodeSniffer.

    ➜  field_image_style git:(2.0.0) curl https://git.drupalcode.org/project/field_image_style/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 17793    0 17793    0     0  41761      0 --:--:-- --:--:-- --:--:-- 42263
    patching file .gitlab-ci.yml
    patching file field_image_style.module
    patching file 'src/Plugin/Field/FieldFormatter/ImageStyleImageFormatter.php'
    patching file 'src/Plugin/Field/FieldType/ImageStyleItem.php'
    ➜  field_image_style git:(2.0.0) ✗ cd ..
    ➜  contrib git:(main) ✗ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig field_image_style
    ➜  contrib git:(main) ✗

    It also passed the phpcs using the Gitlab CI.

    Moving this to RTBC.
    Thank you.

Production build 0.71.5 2024