Fix the issues reported by phpcs

Created on 31 May 2022, over 2 years ago
Updated 31 July 2024, 4 months ago
šŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India Meeni_Dhobale

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • šŸ‡®šŸ‡³India arpitk

    The patch #4 applied cleanly however there is still following errors/warnings reported :

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/commerce_simple_stock/src/EventSubscriber/OrderEventSubscriber.php
    -------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    -------------------------------------------------------------------------------------------------------------------------
    52 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    166 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -------------------------------------------------------------------------------------------------------------------------

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/commerce_simple_stock/src/Form/StockInventoryControlForm.php
    -------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    -------------------------------------------------------------------------------------------------------------------
    142 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    145 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    164 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -------------------------------------------------------------------------------------------------------------------

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/commerce_simple_stock/src/OrderProcessor/AvailabilityOrderProcessor.php
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------
    30 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ------------------------------------------------------------------------------------------------------------------------------

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/commerce_simple_stock/js/inventory_control.js
    ----------------------------------------------------------------------------------------------------
    FOUND 44 ERRORS AFFECTING 22 LINES
    ----------------------------------------------------------------------------------------------------
    3 | ERROR | [x] Space before opening parenthesis of function call prohibited
    4 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    4 | ERROR | [x] Expected 1 space before opening brace; found 0
    11 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    11 | ERROR | [x] Expected 1 space before opening brace; found 0
    13 | ERROR | [x] Functions must not contain multiple empty lines in a row; found 2 empty lines
    15 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    17 | ERROR | [x] Expected 1 space before "=="; 0 found
    17 | ERROR | [x] Expected 1 space after "=="; 0 found
    23 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    23 | ERROR | [x] Expected 1 space before opening brace; found 0
    29 | ERROR | [x] Whitespace found at end of line
    30 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    30 | ERROR | [x] Expected 1 space before opening brace; found 0
    37 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    42 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    53 | ERROR | [x] Whitespace found at end of line
    66 | ERROR | [x] Expected 1 space before "+"; 0 found
    66 | ERROR | [x] Expected 1 space after "+"; 0 found
    71 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    79 | ERROR | [x] Expected 1 space before "+"; 0 found
    79 | ERROR | [x] Expected 1 space after "+"; 0 found
    79 | ERROR | [x] Expected 1 space before "+"; 0 found
    79 | ERROR | [x] Expected 1 space after "+"; 0 found
    80 | ERROR | [x] Expected 1 space before "+"; 0 found
    80 | ERROR | [x] Expected 1 space after "+"; 0 found
    80 | ERROR | [x] Expected 1 space before "+"; 0 found
    80 | ERROR | [x] Expected 1 space after "+"; 0 found
    80 | ERROR | [x] Expected 1 space before "+"; 0 found
    80 | ERROR | [x] Expected 1 space after "+"; 0 found
    81 | ERROR | [x] Expected 1 space before "+"; 0 found
    81 | ERROR | [x] Expected 1 space after "+"; 0 found
    81 | ERROR | [x] Expected 1 space before "+"; 0 found
    81 | ERROR | [x] Expected 1 space after "+"; 0 found
    82 | ERROR | [x] Expected 1 space before "+"; 0 found
    82 | ERROR | [x] Expected 1 space after "+"; 0 found
    82 | ERROR | [x] Expected 1 space before "+"; 0 found
    82 | ERROR | [x] Expected 1 space after "+"; 0 found
    82 | ERROR | [x] Expected 1 space before "+"; 0 found
    82 | ERROR | [x] Expected 1 space after "+"; 0 found
    89 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    90 | ERROR | [x] Inline control structures are not allowed
    98 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
    99 | ERROR | [x] Equals sign not aligned correctly; expected 1 space but found 2 spaces
    ----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 44 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------

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

    Working on updating the patch.

    Thanks!

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India arpitk

    Here is the updated patch. Please review.

    Thanks!

  • Status changed to RTBC over 1 year ago
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi arpitk

    I applied your patch #8 to my local with Drupal 9.5.9 and confirmed that your patch fixed all the PHPCS errors/issue,

    Please look at the screenshots I provided for your reference.

    Thank you.

  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    The patch could fix the reported errors/warnings, but it contains wrong changes.

     /**
    - * Class CommerceSimpleStockController.
    + * Implementation of Commerce Simple Stock Controller.
      */

    There is no need to start a class description with Implementation of, especially when it is followed by the class name (which is essentially saying the class is an implementation of itself). That description does not say what the class does.

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

    The property description is only given before the @var line. The entity type manager. is a sufficient description.

    +  /**
    +   * The config factory service.
    +   *
    +   * @var \Drupal\Core\Config\ConfigFactoryInterface
    +   */
    +  protected $configFactory;
    +

    There is no need to say it is a service.

    -    $events['commerce_order.place.post_transition'] = ['postTransitionOrder', -100];
    -    $events['commerce_order.cancel.post_transition'] = ['postTransitionCancelOrder', -100];
    +    $events['commerce_order.place.post_transition'] = ['postTransitionOrder',
    +      -100,
    +    ];
    +    $events['commerce_order.cancel.post_transition'] = ['postTransitionCancelOrder',
    +      -100,
    +    ];
    -          if ($order && !in_array($order->getState()->value, ['draft', 'canceled'])) {
    +          if ($order && !in_array($order->getState()->value, ['draft',
    +            'canceled',
    +          ])) {
                 $purchasedEntity = $item->getPurchasedEntity();

    Code lines are not required to be shorter than 81 characters. Line length and wrapping ā†’ , part of the Drupal coding standards, says:

    • Lines containing longer function names, function/class definitions, variable declarations, etc are allowed to exceed 80 characters.
    • Control structure conditions may exceed 80 characters, if they are simple to read and understand.

    (Emphasis is mine.)

    In both the cases, the existing code is simpler to read and understand.

    +  /**
    +   * Constructs a new StockInventoryControlForm object.
    +   *
    +   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    +   *   The entity type manager.
    +   */

    The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.

  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India arpitk

    Hi here is the updated patch addressing #10. Please review.

    Thanks!

  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    -    if(e.keyCode==13 && ($(this).val() != '')) {
    +    if(e.keyCode == 13 && ($(this).val() != '')) {

    There must be a space between if and the opening parenthesis.

    +   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    +   *   The config factory service.

    There is no need to say it is a service.

     /**
    - * Class StockInventoryConfigForm.
    + * Implementing Stock Inventory Config Form.
      */
    

    That description is still wrong for the reasons I reported in my previous comment.

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

    See my previous comment for what needs to be changed.

    +  /**
    +   * Constructs a new StockInventoryControlForm object.
    +   *

    That has not been changed since my previous comment.

    +  /**
    +   * The config factory service.
    +   *
    +   * @var \Drupal\Core\Config\ConfigFactoryInterface
    +   */
    +  protected $configFactory;
    

    It is sufficient to say The config factory.

    +  /**
    +   * Constructs a new AvailabilityOrderProcessor object.
    +   *
    +   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    +   *   The config factory service.
    +   */
    

    That needs to be changes as per my previous comment, which holds true for every constructor description where the class namespace is missing.

    Furthermore, the issue summary should always describe what the issue is trying to fix and, in the case of coding standards issues, show which command and arguments have been used and which report that command shown. In this way, project maintainers can verify the patch/MR fixes all the warnings/errors.

  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India sakthi_dev

    Created a patch based on comment #12. Please review.

  • šŸ‡®šŸ‡³India pray_12

    Hi,
    Above patch addressed the #12 comments, but there are still few errors and warnings found that need correction.

  • šŸ‡®šŸ‡³India dev16.addweb

    Hi here is the updated patch addressing #14. Please review.

    Thanks!

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    6 months ago
    Total: 181s
    #190936
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    6 months ago
    Total: 144s
    #190952
  • Status changed to Needs work 4 months ago
  • Hi @silvi.addweb,

    Applied your patch, it was applied not-so successfully and only fixed few errors, there are still errors remaining. Please see below:

    āžœ  commerce_simple_stock git:(8.x-1.x) curl https://www.drupal.org/files/issues/2024-06-04/commerce_simple_stock-3283344-15.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  9857  100  9857    0     0  36430      0 --:--:-- --:--:-- --:--:-- 37479
    patching file src/Controller/CommerceSimpleStockController.php
    patching file src/EventSubscriber/OrderEventSubscriber.php
    Hunk #2 FAILED at 15.
    Hunk #3 succeeded at 38 (offset -10 lines).
    Hunk #4 succeeded at 57 (offset -10 lines).
    Hunk #5 succeeded at 171 (offset -10 lines).
    1 out of 5 hunks FAILED -- saving rejects to file src/EventSubscriber/OrderEventSubscriber.php.rej
    patching file src/Form/StockInventoryConfigForm.php
    patching file src/Form/StockInventoryControlForm.php
    patching file src/OrderProcessor/AvailabilityOrderProcessor.php
    āžœ  commerce_simple_stock git:(8.x-1.x) āœ— cd ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig commerce_simple_stock
    
    FILE: ...ple_stock/templates/commerce-simple-stock-inventory-control-form.html.twig
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     35 | ERROR | [x] Expected 1 newline at end of file; 0 found
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...contrib/commerce_simple_stock/src/EventSubscriber/OrderEventSubscriber.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     8 | WARNING | [x] Unused use statement
     9 | WARNING | [x] Unused use statement
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    Time: 293ms; Memory: 10MB

    Kindly check

    Thanks,
    Jake

  • Pipeline finished with Canceled
    4 months ago
    Total: 115s
    #239099
  • Status changed to Needs review 4 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    It is the merge request to review.

  • Pipeline finished with Success
    4 months ago
    Total: 135s
    #239101
Production build 0.71.5 2024