Fix the issues reported by phpcs

Created on 15 June 2023, over 1 year ago
Updated 17 August 2023, over 1 year ago

Problem/Motivation

Getting following error/warnings

FILE: D:\xampp\htdocs\drupal_10\web\modules\contrib\image_url_formatter\README.md
---------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------
39 | WARNING | Line exceeds 80 characters; contains 86 characters
---------------------------------------------------------------------------------

FILE: D:\xampp\htdocs\drupal_10\web\modules\contrib\image_url_formatter\src\Plugin\Field\FieldFormatter\ImageUrlFormatter.php
-----------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
-----------------------------------------------------------------------------------------------------------------------------
58 | ERROR | Parameter $image_style_storage is not described in comment
134 | WARNING | Line exceeds 80 characters; contains 118 characters
135 | WARNING | Line exceeds 80 characters; contains 133 characters
136 | WARNING | Line exceeds 80 characters; contains 129 characters
-----------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Run following command:

phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml image_url_formatter/

Proposed resolution

Above error/warnings need to be fixed

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India arti_parmar

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

Comments & Activities

  • Issue created by @arti_parmar
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India arti_parmar

    Kindly review patch.

  • Status changed to Needs work over 1 year ago
  • 🇵🇭Philippines kenyoOwen

    Hi arti_parmar

    After I applied your patch that also has errors, there are still errors and warnings remaining.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml image_url_formatter

    FILE: /Users/studenttrainees/Project10/drupalorg10/docroot/modules/contrib/image_url_formatter/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 7 ERRORS AND 3 WARNINGS AFFECTING 6 LINES
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    16 | ERROR | [x] Whitespace found at end of line
    58 | ERROR | [ ] Parameter $image_style_storage is not described in comment
    128 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
    128 | ERROR | [x] Array indentation error, expected 8 spaces but found 5
    134 | WARNING | [ ] Line exceeds 80 characters; contains 117 characters
    134 | ERROR | [x] No space found before comment text; expected "// $element['url_type'][0]['#description'] = $this->t("Like:
    | | 'http://example.com/sites/default/files/image.png'");" but found "//$element['url_type'][0]['#description'] = $this->t("Like:
    | | 'http://example.com/sites/default/files/image.png'");"
    135 | WARNING | [ ] Line exceeds 80 characters; contains 132 characters
    135 | ERROR | [x] No space found before comment text; expected "// $element['url_type'][1]['#description'] = $this->t("With leading slash, no base URL, like:
    | | '/sites/default/files/image.png'");" but found "//$element['url_type'][1]['#description'] = $this->t("With leading slash, no base URL, like:
    | | '/sites/default/files/image.png'");"
    136 | WARNING | [ ] Line exceeds 80 characters; contains 128 characters
    136 | ERROR | [x] No space found before comment text; expected "// $element['url_type'][2]['#description'] = $this->t("No base URL or leading slash, like:
    | | 'sites/default/files/image.png'");" but found "//$element['url_type'][2]['#description'] = $this->t("No base URL or leading slash, like:
    | | 'sites/default/files/image.png'");"
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Time: 171ms; Memory: 10MB

  • Assigned to nitin_lama
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India arti_parmar

    Hi, @kenyoOwen,
    PHPCBF CAN FIX THE SNIFF VIOLATIONS AUTOMATICALLY,
    so first of all please run phpcbf and then check only those error is showing which i fixed.

  • Assigned to nitin_lama
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India nitin_lama India

    @arti_parmar, the mentioned errors/warning in the IS are fixed but there are still more errors/warning left.

    FILE: /home/system/Documents/contribution/image_url_formatter/image_url_formatter.module
    ----------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------
     38 | ERROR | Type hint "array" missing for $variables
    ----------------------------------------------------------------------------------------
    
    FILE: /home/system/Documents/contribution/image_url_formatter/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php
    -------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------
     234 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -------------------------------------------------------------------------------------------------------------------
    
    Time: 34ms; Memory: 6MB
    
    
  • 🇮🇳India nitin_lama India

    Updated patch with the remaining phpcs fixes.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Assigned to kartiktandon
  • Issue was unassigned.
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The latest patch does not even fix all the errors/warnings the other patches fixed.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India mrinalini9 New Delhi

    Not able to apply patch #11, getting some error saying: "fatal: unrecognized input".
    So, added a patch that consists of all the phpcs errors/warnings fixes, please review it.

    Thanks!

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -  - Install the Image URL Formatter module as you would normally install a contributed
    +  - Install the Image URL Formatter module as you would normally install a
    +  contributed

    Since that text is part of a list, the last line must be indented.
    Also, the line after contributed should be written in the same line with contributed.
    Then, since that text is changed, the text suggested in the README template → should be used.

    Install as you would normally install a contributed Drupal module. For further
    information, see
    [Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
    
     /**
      * @file
    - * Add an URL formatter for image field
    + * Add an URL formatter for image field.
      */

    The usual description is Hook implementations for the [module name] module. where [module name] is the module name shown in the .info.yml file.

    +   * @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
    +   *   The Image Style Storage.
    

    Only the first word in the description must be capitalized.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India mrinalini9 New Delhi

    Updated patch #15 by addressing #16, please review it.

    Thanks!

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +1. After installation of this module you'll get a new
     format type "Image URL" you can assign to any Image Field
     in a Content Type. Just go to the Type's "Manage Display"
     and choose "Image URL" instead of "Image" from the Format
     Combo-Box.
    

    The lines after the first one must be indented.

    +  - Install the Image URL Formatter module as you would normally install a
    +    contributed Drupal module. For further information, see
    +    [Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).

    The first sentence does not need to say the module name. The README template uses the following text.

    Install as you would normally install a contributed Drupal module. For further
    information, see
    [Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
    
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India sakthi_dev

    Please review. Addressed all the changes in comment #18.

  • Status changed to Fixed over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024