Fix the issues reported by phpcs

Created on 14 February 2023, almost 2 years ago
Updated 6 June 2024, 7 months ago

GitLab Ci reports PHP_CodeSniffer warnings/errors which should be fixed. The ones still to be fixed are the following ones.

FILE: ...popup-3341557/src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
--------------------------------------------------------------------------------
  9 | ERROR   | [x] Use statements should be sorted alphabetically. The first
    |         |     wrong one is Drupal\Core\Config\ConfigFactoryInterface.
    |         |     (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses)
 89 | WARNING | [ ] Line exceeds 80 characters; contains 92 characters
    |         |     (Drupal.Files.LineLength.TooLong)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: ...web/modules/custom/image_popup-3341557/src/Form/EditorImagePopupDialog.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 10 | ERROR | [x] Use statements should be sorted alphabetically. The first
    |       |     wrong one is Drupal\Core\Ajax\AjaxResponse.
    |       |     (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: ...41557/web/modules/custom/image_popup-3341557/src/Controller/ImagePopup.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 11 | ERROR | [x] Use statements should be sorted alphabetically. The first
    |       |     wrong one is Drupal\Core\Entity\EntityTypeManagerInterface.
    |       |     (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
Time: 181ms; Memory: 6MB

 
 

šŸ“Œ Task
Status

Needs review

Version

2.0

Component

Code

Created by

šŸ‡®šŸ‡³India indrapatil Bangalore

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

  • Issue created by @indrapatil
  • Status changed to Needs work almost 2 years ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    The issue summary needs to be updated to describe exactly what needs to be changed, and why. At least, it needs to report:

    • Which tool has been used to check the code
    • Which arguments have been used for that tool
    • What report that tool shown
  • šŸ‡®šŸ‡³India indrapatil Bangalore

    phpcs --standard="Drupal,DrupalPractice" --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml image_popup-3341557/

    FILE: /var/www/html/drupal8/web/modules/image_popup-3341557/src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ------------------------------------------------------------------------------------------------------------------------
    246 | WARNING | [ ] ImageStyle::load calls should be avoided in classes, use dependency injection instead
    282 | WARNING | [x] A comma should follow the last multiline array item. Found: )
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal8/web/modules/image_popup-3341557/src/Controller/ImagePopup.php
    -----------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------------------
    17 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
    30 | WARNING | ImageStyle::load calls should be avoided in classes, use dependency injection instead
    35 | WARNING | ImageStyle::load calls should be avoided in classes, use dependency injection instead
    -----------------------------------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal8/web/modules/image_popup-3341557/src/Form/EditorImagePopupDialog.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 5 ERRORS AFFECTING 5 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
    121 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    144 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    201 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    208 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    265 | ERROR | [ ] The array declaration extends to column 87 (the limit is 80). The array content should be split up over multiple lines
    ------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal8/web/modules/image_popup-3341557/image_popup.module
    ------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 2 LINES
    ------------------------------------------------------------------------------
    1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
    1 | ERROR | [x] Missing file doc comment
    37 | ERROR | [x] Missing function doc comment
    ------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------

    Time: 124ms; Memory: 12MB

  • @indra-patil opened merge request.
  • @indra-patil opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs work almost 2 years ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    +/**
    + * @file
    + * Implements image popup module.
    + */
    

    The top comment for a module should not start with Implements. That is for hook comments.

         if (!empty($image_style)) {
    -      $image_style = ImageStyle::load($image_style);
    +      $image_style = $this->fileStorage->load($image_style);
    

    The file storage service is not the one to load image styles.

  • First commit to issue fork.
  • Merge request !4Phpcs 3341557 ā†’ (Open) created by kkalashnikov
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs review almost 2 years ago
  • šŸ‡®šŸ‡³India kkalashnikov Ghaziabad, India

    Updated changes with this MR

  • Status changed to Needs work almost 2 years ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    - * @package Drupal\image_popup\Controller
    + * @package Drupal\image_popup\Controller.

    That line is already correct.

    +  /**
    +   * The Get EntityTypeManagerInterface.
    +   *
    +   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
    +   */
    +  protected $entityTypeManager;

    The first comment does not describe that property.

    +  /**
    +   * Class constructor.
    +   *
    +   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity
    +   *   The Entity type manager service.
    +   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    +   *   Get entity_type_manager.
    +   */
    +  public function __construct(EntityTypeManagerInterface $entity, EntityTypeManagerInterface $entity_type_manager) {
    +    $this->entityTypeManager = $entity_type_manager;
    +  }

    A class constructor is described differently.

    +    $data_img_popup = $file->uuid() . ':' .
    +    $form_state->getValue(['attributes', 'alt']) . ':' .
    +    $image_style . ':' .
    +    $image_style_popup . ':' . $align;

    If that line is going to be split in multiple lines, the lines after the first should be indented.

        * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
        *   The entity field manager.
    +   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    +   *   Get entity_type_manager.

    See the $entity_field_manager line.

  • Assigned to arti_parmar
  • Assigned to nitin_lama
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    I get a slightly different report, probably because I am using a more recent version of the rule-sets used for Drupal coding standards.

  • šŸ‡®šŸ‡³India zkhan.aamir

    Hi,

    MR #15 applied successfully.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/image_popup (2.x)
    $ curl https://git.drupalcode.org/project/image_popup/-/merge_requests/4.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 10399    0 10399    0     0  29041      0 --:--:-- --:--:-- --:--:-- 29128
    patching file image_popup.module
    patching file src/Controller/ImagePopup.php
    patching file src/Form/EditorImagePopupDialog.php
    Hunk #1 succeeded at 119 (offset 1 line).
    Hunk #2 succeeded at 142 (offset 1 line).
    Hunk #3 succeeded at 199 (offset 1 line).
    Hunk #4 succeeded at 263 (offset 1 line).
    patching file src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php
    

    Remaining issues.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules
    $ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml image_popup/
    
    FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\image_popup\src\Controller\ImagePopup.php
    --------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------
     58 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    --------------------------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\image_popup\src\Form\EditorImagePopupDialog.php
    --------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------
     237 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    --------------------------------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\image_popup\src\Plugin\Field\FieldFormatter\ImagePopupFieldFormatter.php
    ---------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------------------------------
      89 | WARNING | Line exceeds 80 characters; contains 92 characters
     285 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ---------------------------------------------------------------------------------------------------------------------------------
    
    Time: 356ms; Memory: 12MB
    
  • šŸ‡®šŸ‡³India dev16.addweb

    Please review this patch.

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

    apaderno ā†’ changed the visibility of the branch 3341557-coding-standards to hidden.

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

    apaderno ā†’ changed the visibility of the branch 2.x to hidden.

  • Pipeline finished with Success
    7 months ago
    Total: 155s
    #185866
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs review 7 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    7 months ago
    Total: 250s
    #185929
  • Status changed to RTBC 7 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @silvi.addweb,

    I applied patch #19. It was applied smoothly and fixed all the issues found by phpcs.

    āžœ  image_popup git:(2.x) āœ— curl https://www.drupal.org/files/issues/2024-05-30/3341557-19.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 15393  100 15393    0     0  36537      0 --:--:-- --:--:-- --:--:-- 36476
    patching file image_popup.module
    patching file src/Controller/ImagePopup.php
    patching file src/Form/EditorImagePopupDialog.php
    patching file src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php
    āžœ  image_popup git:(2.x) āœ— ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml image_popup
    āžœ  contrib git:(main) āœ—

    Thank you.

  • Status changed to Needs work 7 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    GitLab CI still reports issues that need to be fixed.

  • Status changed to Needs review 7 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    7 months ago
    Total: 139s
    #192439
Production build 0.71.5 2024