Fix the issues reported by phpcs

Created on 4 February 2023, over 1 year ago
Updated 16 February 2024, 4 months ago

Problem/Motivation

Running $ phpcs --standard=Drupal menu_tree_compare gives the following report.

FILE: ...:\xampp\htdocs\drupal9.5\modules\menu_tree_compare\js\menu_tree_compare.js
   1 | ERROR | [x] End of line character is invalid; expected "\n" but found
     |       |     "\r\n"
   6 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
   8 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
  22 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
  25 | ERROR | [x] Functions must not contain multiple empty lines in a row;
     |       |     found 2 empty lines
  31 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
  39 | ERROR | [x] Expected 1 space after "="; 2 found
  44 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
 105 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but
     |       |     found "true"
 106 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but
     |       |     found "true"
 111 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but
     |       |     found "true"
 116 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but
     |       |     found "true"
 134 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
 134 | ERROR | [x] Expected 1 space before opening brace; found 0
 145 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
 145 | ERROR | [x] Expected 1 space before opening brace; found 0
 177 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found

FILE: D:\xampp\htdocs\drupal9.5\modules\menu_tree_compare\menu_tree_compare.css
  1 | ERROR | [x] End of line character is invalid; expected "\n" but found
    |       |     "\r\n"
  7 | ERROR | [x] Whitespace found at end of line
  8 | ERROR | [x] Whitespace found at end of line
 10 | ERROR | [x] Whitespace found at end of line
 11 | ERROR | [x] Whitespace found at end of line
 20 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 20 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 21 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 21 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 22 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 22 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 23 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 23 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 23 | ERROR | [x] Whitespace found at end of line
 24 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 24 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 24 | ERROR | [x] Whitespace found at end of line
 25 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 25 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 26 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 26 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 26 | ERROR | [x] Whitespace found at end of line
 27 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 27 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 27 | ERROR | [x] Whitespace found at end of line
 28 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
 28 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 1
 52 | ERROR | [x] Expected 1 space before opening brace of class definition; 2
    |       |     found
 53 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4

FILE: ...9.5\modules\menu_tree_compare\src\Controller\MenuTreeCompareController.php
   1 | ERROR   | [x] End of line character is invalid; expected "\n" but found
     |         |     "\r\n"
  11 | ERROR   | [x] Missing class doc comment
  12 | ERROR   | [ ] Missing short description in doc comment
  17 | ERROR   | [ ] Missing short description in doc comment
  18 | ERROR   | [x] Data types in @var tags need to be fully namespaced
  22 | ERROR   | [x] Missing function doc comment
  27 | ERROR   | [x] Missing function doc comment
  37 | ERROR   | [ ] Missing parameter comment
  38 | ERROR   | [ ] Missing parameter comment
  39 | ERROR   | [x] Separate the @param and @return sections by a blank line.
  39 | ERROR   | [ ] Description for the @return value is missing
 172 | ERROR   | [ ] Missing short description in doc comment
 173 | ERROR   | [ ] Missing parameter comment
 189 | WARNING | [ ] Line exceeds 80 characters; contains 90 characters
 193 | ERROR   | [ ] @return doc comment specified, but function has no return
     |         |     statement

FILE: ...mpp\htdocs\drupal9.5\modules\menu_tree_compare\src\Form\MenuChoiceForm.php
 1 | ERROR | [x] End of line character is invalid; expected "\n" but found
   |       |     "\r\n"

Proposed resolution

Fix these errors and warnings.

📌 Task
Status

Needs work

Version

1.0

Component

Code

Created by

🇮🇳India Kamlesh Kishor Jha Jaipur

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 @Kamlesh Kishor Jha
  • @kamlesh-kishor-jha opened merge request.
  • 🇮🇳India Kamlesh Kishor Jha Jaipur

    Created mr for this issue.
    Please review this mr.
    Thanks.

  • Issue was unassigned.
  • Status changed to Needs work about 1 year ago
  • 🇵🇭Philippines paraderojether

    Hi Kamlesh Kishor Jha

    I reviewed MR!1, and confirmed the it fixes all the errors and warnings that you addressed. However, I'm getting these new errors and warnings shown below:

    FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/menu_tree_compare/README.txt
    ---------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------
    33 | WARNING | Line exceeds 80 characters; contains 148 characters
    ---------------------------------------------------------------------------------------------------

    FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/menu_tree_compare/src/Form/MenuChoiceForm.php
    ---------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AND 4 WARNINGS AFFECTING 7 LINES
    ---------------------------------------------------------------------------------------------------------------------------------------------
    9 | WARNING | [x] Unused use statement
    10 | WARNING | [x] Unused use statement
    27 | ERROR | [x] Missing function doc comment
    31 | ERROR | [x] Missing function doc comment
    50 | ERROR | [x] Expected 1 space after FOREACH keyword; 0 found
    56 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    62 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ---------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------------------

    FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/menu_tree_compare/src/Controller/MenuTreeCompareController.php
    -------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------
    270 | WARNING | Unused variable $key.
    -------------------------------------------------------------------------------------------------------------------------------------

    Time: 352ms; Memory: 12MB

    Please check.
    Thank You.

  • Assigned to akshaydalvi212
  • 🇮🇳India akshaydalvi212

    I will resolve the remaining issues reported above.

  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India akshaydalvi212

    Resolved the issues kindly review.

  • @akshaydalvi212 opened merge request.
  • Status changed to Needs work about 1 year ago
  • 🇮🇳India Mahima_Mathur23

    Some of the comments needs more description like the Constructor of "MenuTreeCompareController" class.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Ashutosh Ahirwal India

    Providing patch with solution
    please review it.

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +/**
    + * Class for MenuTreeCompareController.
    + */

    The documentation comment for a class must not start with Class for followed by the class name. It must describe the class purpose.

    +  /**
    +   * {@inheritdoc}
    +   */
       public function __construct(MenuLinkTreeInterface $menu_link_tree, MenuLinkManagerInterface $menu_link_manager) {

    {@inheritdoc} is not used for class constructors.

        * @param string $from
    +   *   Return string value.
        * @param string $to
    +   *   Return string value.

    A parameter description must not start with Return.
    Also, the description must say what that parameter is, not what its type is.

        * @return mixed
    +   *   Return values
        */

    The return value description must not start with Return.
    That description is so vague that could be use for every return value.

       /**
    +   * Function isCompatiblePluginId().
    +   *
        * @param string $plugin_id
    +   *   Return string value.
        *
        * @return bool
        *   Whether the plugin ID is supported.

    The method descriptions must not start with Function nor repeat the method name.
    The parameter description is not correct, for the same reason given earlier.

    -   * @return array
    -   *   A render arrays.

    The plural is not used with indefinite articles.

  • Assigned to himanshu_jhaloya
  • 🇮🇳India himanshu_jhaloya Mandsaur

    created patch please review

  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Mahima_Mathur23

    @himanshu_jhaloya, Please work upon the previous patch and incorporate @apaderno's suggestions.
    Otherwise we start from square one everytime.

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    @Mahima_Mathur23 is correct. The previous patch did not contain the following wrong change.

    -    /**  @var \Drupal\Core\Menu\MenuLinkTreeElement  $data */
    -    foreach ($tree as $key => $data) {
    +    /**
    +     *  @var \Drupal\Core\Menu\MenuLinkTreeElement  $data
    +     *
    +     */
    +    foreach ($tree as $data) {

    In /** @var \Drupal\Core\Menu\MenuLinkTreeElement $data */ there are two extra spaces, but that needs to be a single line.

    Eventually, the choice to only use the Drupal standard for the report could be questioned, but the patch should fix what reported by phpcs --standard=Drupal.

  • Assigned to akshaydalvi212
  • 🇮🇳India akshaydalvi212

    I will work on the MR as I raised at #7 and as suggested in #9 and #12 will update the MR accordingly.

  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India akshaydalvi212

    Kindly review the MR and sorry was not in a condition to work on it for the last 2-3 days.

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -(function($, Drupal ) {
    +(function ($, Drupal ) {
       Drupal.behaviors.menu_tree_compare = {

    There must not be spaces between the last argument and the closing parenthesis.

    -      var container_height =  Math.max.apply( Math, [ left_height, right_height ] ) + 20;
    +      var container_height = Math.max.apply( Math, [ left_height, right_height ] ) + 20;

    Since that code is changed, the space before the first argument and before the last argument must be removed.

    +/**
    + * Provides controller actions for compare and mapping of menus.
    + */

    Since it uses mapping, it must also say comparing.
    Also, it is not mapping of menus, but menu mapping.

    +  /**
    +   * Constructs a MenuTreeCompareController object.
    +   *
    +   * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_link_tree
    +   *   The menu link tree service.
    +   * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
    +   *   The menu link manager service.
    +   */
       public function __construct(MenuLinkTreeInterface $menu_link_tree, MenuLinkManagerInterface $menu_link_manager) {

    The short description is missing the class namespace.

       /**
    -   * Controller entry point.
    +   * Summary of compare.
        *
    -   * @param string $from
    -   * @param string $to
    -   * @return mixed
    +   * @param mixed $from
    +   *   The from.
    +   * @param mixed $to
    +   *   The to.
    +   *
    +   * @return array
    +   *   It will return array.
        */
       public function compare($from, $to) {

    Short descriptions must not start with Summary of.
    The parameter descriptions are wrong.
    The return value description must describe the return value, not its type. They must not start with It will return.

       /**
    +   * Summary of isCompatiblePluginId..
    +   *
        * @param string $plugin_id
    +   *   The plugin id.

    The short description is wrong for the same reason the previous short description is wrong. It also ends with two periods instead of one.
    id is misspelled, since the correct spelling is ID.

       /**
    -   * Returns an output structure for rendering a menu tree.
    +   * Summary of enrichMenuTree.

    The existing description is already correct. Eventually, it could be changed to Renders a menu tree.

        * @param array $tree
    -   *   A  structure representing the tree as returned from MenuLinkTreeInterface::build().
    +   *   The tree.

    The existing description is already correct.

    -   *   The mapping of items on the left and on the right.
    -   *
    -   * @return array
    -   *   A render arrays.
    -   *
    -   * @see MenuLinkTreeInterface::build()
    +   *   The mapping.
        */

    The return value description cannot be removed. Eventually it needs to be corrected, since A must be followed by a singular word. (arrays is a plural word.)
    The parameter description is already correct.

    +  /**
    +   * Constructs a \Drupal\system\ConfigFormBase object.
    +   *
    +   * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
    +   *   The entity type manager service.
    +   */
       public function __construct(EntityTypeManager $entity_type_manager) {

    Since that is the MenuChoiceForm constructor, it cannot construct a \Drupal\system\ConfigFormBase object.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Also, the report given in the issue summary is for the following files.

    • js/menu_tree_compare.js
    • menu_tree_compare.css
    • src/Controller/MenuTreeCompareController.php
    • src/Form/MenuChoiceForm.php

    The MR is changing the following files.

    • README.txt
    • js/menu_tree_compare.js
    • menu_tree_compare.css
    • src/Controller/MenuTreeCompareController.php
    • src/Form/MenuChoiceForm.php

    The report does show anything for the README.txt file.

  • 🇩🇰Denmark ressa Copenhagen

    Manually attaching patches is being phased out, and you should create a patch and Merge Request with the Gitlab integration.

    DrupalCI and all patch testing will be turned off on July 1, 2024

Production build 0.69.0 2024