Fix the issues reported by phpcs

Created on 5 May 2023, over 1 year ago
Updated 21 August 2024, 4 months ago

Problem/Motivation

FILE: ...tml/contribution/drupal10/web/modules/contrib/commerce_promo_bar/README.md
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
--------------------------------------------------------------------------------
14 | WARNING | Line exceeds 80 characters; contains 85 characters
36 | WARNING | Line exceeds 80 characters; contains 84 characters
--------------------------------------------------------------------------------

FILE: .../web/modules/contrib/commerce_promo_bar/src/Plugin/Block/PromoBarBlock.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
134 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
--------------------------------------------------------------------------------

FILE: ...upal10/web/modules/contrib/commerce_promo_bar/src/Event/PromoBarEvents.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
5 | ERROR | [x] Missing class doc comment
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...rupal10/web/modules/contrib/commerce_promo_bar/commerce_promo_bar.info.yml
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
10 | ERROR | [x] Expected 1 newline at end of file; 2 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...ion/drupal10/web/modules/contrib/commerce_promo_bar/css/promo_bar.form.css
--------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------
22 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
23 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
57 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: .../modules/contrib/commerce_promo_bar/templates/commerce-promo-bar.html.twig
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
36 | ERROR | [x] Expected 1 newline at end of file; 2 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: .../drupal10/web/modules/contrib/commerce_promo_bar/commerce_promo_bar.module
--------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
--------------------------------------------------------------------------------
38 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
44 | ERROR | [x] Data types in @var tags need to be fully namespaced
67 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | ]
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 1.73 secs; Memory: 14MB

Steps to reproduce

Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig commerce_promo_bar/

Proposed resolution

Fix the issues reported for Drupal and DrupalPractice coding standards.

Remaining tasks

Review.

๐Ÿ“Œ Task
Status

Closed: outdated

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

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 @urvashi_vora
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7 updated deps
    last update over 1 year ago
    2 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines kenyoOwen

    Hi urvashi_vora

    I applied patch Fixed-all-issues.patch โ†’ to the โ€œCommerce Promo Barโ€ module and confirmed that the mentioned PHPCS issues are resolved. Please see the screenshots attached.

    For your review.
    Thank you.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +/**
    + * Implements class PromoBarEvents.
    + */

    Class descriptions must not start with Implements class nor repeat the class name. Instead, they should describe the class purpose.

    +   * @param \Drupal\Component\Datetime\TimeInterface $time
    +   *   The time service.
        */
       public function __construct(array $configuration,
       $plugin_id,
       $plugin_definition,
    -    EntityTypeManagerInterface $entity_type_manager,
    +  EntityTypeManagerInterface $entity_type_manager,
       CurrentStoreInterface $current_store,
    -  AccountProxyInterface $current_user) {
    +  AccountProxyInterface $current_user,
    +  TimeInterface $time) {

    Since that code is edited, it should also be edited to put the method declaration of a single line, since that is how Drupal coding standards say to format method/function declarations.

    -      $container->get('current_user')
    +      $container->get('current_user'),
    +      $container->get('datetime.time'),
         );

    The comma after the last argument is only allowed on PHP 8. If that module does not explicitly require PHP 8, that comma must be removed.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7 updated deps
    last update over 1 year ago
    2 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Soham Sengupta

    Hi, Updated the patch with the suggested changes.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    - *   - elements: An associative array containing the commerce promo bar information and any
    - *     fields attached to the entity.
    + *   - elements: An associative array
    + *     It contains the commerce promo bar information and
    + *     any fields attached to the entity.

    An associative array containing the commerce promo bar information and any fields attached to the entity. was already correct; it was just necessary to reformat the text to avoid lines longer than 80 characters.

    +/**
    + * Defines events for the commerce_promo_bar module.
    + */
     final class PromoBarEvents {
     

    Class descriptions do not need to contain the module machine name.
    The verb should be Handles, and events should be better described as promo events.

    +  /**
    +   * Constructor for the Promo bar block.

    Short descriptions for constructors are Constructs a new [class name] object. where [class name] is replaced by the class name (namespace included).

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7 updated deps
    last update over 1 year ago
    2 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Soham Sengupta

    Thanks, I have updated the patch with the suggested changes, however I was unable to include the namespace of the class in the block constructor short description, as it was exceeding 80characters and the short description should be in a single line.

  • Status changed to Needs work 4 months ago
  • Hi @Soham Sengupta,

    After applying the patch you provided, new errors/warnings were reported. Please see:

    โžœ  commerce_promo_bar git:(1.0.x) curl https://www.drupal.org/files/issues/2023-05-06/3358410-7.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  7142  100  7142    0     0  18387      0 --:--:-- --:--:-- --:--:-- 18794
    patching file README.md
    Hunk #2 FAILED at 33.
    1 out of 2 hunks FAILED -- saving rejects to file README.md.rej
    patching file commerce_promo_bar.info.yml
    patching file commerce_promo_bar.module
    Reversed (or previously applied) patch detected!  Assume -R? [n] y
    Hunk #1 succeeded at 36 (offset 1 line).
    Hunk #2 succeeded at 66 (offset 2 lines).
    patching file css/promo_bar.form.css
    patching file src/Event/PromoBarEvents.php
    Hunk #1 FAILED at 2.
    1 out of 1 hunk FAILED -- saving rejects to file src/Event/PromoBarEvents.php.rej
    patching file src/Plugin/Block/PromoBarBlock.php
    Hunk #1 succeeded at 15 (offset 3 lines).
    Hunk #2 succeeded at 53 with fuzz 1.
    Hunk #3 FAILED at 74.
    Hunk #4 FAILED at 96.
    Hunk #5 FAILED at 138.
    3 out of 5 hunks FAILED -- saving rejects to file src/Plugin/Block/PromoBarBlock.php.rej
    patching file templates/commerce-promo-bar.html.twig
    Hunk #1 FAILED at 34.
    1 out of 1 hunk FAILED -- saving rejects to file templates/commerce-promo-bar.html.twig.rej
    โžœ  commerce_promo_bar git:(1.0.x) โœ— ..
    โžœ  contrib git:(master) โœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig commerce_promo_bar
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/commerce_promo_bar/README.md
    --------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------------------------------
     36 | WARNING | Line exceeds 80 characters; contains 84 characters
     37 | WARNING | Line exceeds 80 characters; contains 81 characters
    --------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/commerce_promo_bar/commerce_promo_bar.module
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
    ------------------------------------------------------------------------------------------------------------------------
     39 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
     45 | ERROR   | [x] Data types in @var tags need to be fully namespaced
     69 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/commerce_promo_bar/templates/commerce-promo-bar.html.twig
    -------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------
     38 | ERROR | [x] Expected 1 newline at end of file; 2 found
    -------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 638ms; Memory: 14MB

    Kindly check

    Thanks,
    Jake

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    avpaderno โ†’ changed the visibility of the branch 3358410-fix-the-issues to hidden.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Let's create a merge request, now that patches are no longer tested.

  • Pipeline finished with Success
    4 months ago
    Total: 131s
    #259972
  • Pipeline finished with Success
    4 months ago
    Total: 172s
    #259978
  • Status changed to Closed: outdated 4 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Actually, no PHP_CodeSniffer errors/warnings are reported before doing any change.

Production build 0.71.5 2024