Fix the issues reported by phpcs

Created on 29 June 2023, 12 months ago
Updated 8 February 2024, 5 months ago

Problem/Motivation

Some phpcs issues were found in the module.

FILE: /Applications/MAMP/htdocs/development/web/modules/contrib/menu_trail_by_path/src/MenuTrailByPathActiveTrail.php
-------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 17 ERRORS AND 6 WARNINGS AFFECTING 23 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------
   5 | WARNING | [x] Unused use statement
  13 | WARNING | [x] Unused use statement
  39 | ERROR   | [ ] Missing short description in doc comment
  42 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 3
  44 | ERROR   | [ ] Missing short description in doc comment
  49 | ERROR   | [ ] Missing short description in doc comment
  64 | ERROR   | [ ] Missing parameter comment
  65 | ERROR   | [ ] Missing parameter comment
  66 | ERROR   | [ ] Missing parameter comment
  67 | ERROR   | [ ] Missing parameter comment
  68 | ERROR   | [ ] Missing parameter comment
  69 | ERROR   | [ ] Missing parameter comment
  70 | ERROR   | [ ] Missing parameter comment
  71 | ERROR   | [ ] Missing parameter comment
  78 | ERROR   | [x] Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
 128 | WARNING | [ ] Line exceeds 80 characters; contains 86 characters
 133 | ERROR   | [x] Expected "\Drupal\Core\Menu\MenuLinkInterface|null" but found "\Drupal\Core\Menu\MenuLinkInterface|NULL" for function return type
 134 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
 171 | WARNING | [ ] Line exceeds 80 characters; contains 106 characters
 172 | WARNING | [ ] Line exceeds 80 characters; contains 125 characters
 174 | ERROR   | [ ] Description for the @return value is missing
 216 | ERROR   | [ ] Missing short description in doc comment
 217 | ERROR   | [ ] Description for the @return value is missing
-------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

FILE: /Applications/MAMP/htdocs/development/web/modules/contrib/menu_trail_by_path/src/MenuTrailByPathServiceProvider.php
-------------------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------------------------------
  5 | ERROR | [x] When importing a class with "use", do not include a leading \
  6 | ERROR | [x] When importing a class with "use", do not include a leading \
 16 | ERROR | [x] Expected 1 blank line before function; 0 found
 23 | ERROR | [x] Expected 1 blank line after function; 0 found
 24 | ERROR | [x] The closing brace for the class must have an empty line before it
-------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

FILE: /Applications/MAMP/htdocs/development/web/modules/contrib/menu_trail_by_path/tests/src/Functional/MenuTrailByPathActiveTrailHtmlClassTest.php
---------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 24 ERRORS AND 3 WARNINGS AFFECTING 23 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------
  41 | WARNING | [ ] Line exceeds 80 characters; contains 84 characters
  43 | ERROR   | [x] Data types in @var tags need to be fully namespaced
  47 | ERROR   | [ ] Missing short description in doc comment
  58 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  61 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  62 | ERROR   | [x] Short array syntax must be used to define arrays
  62 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
  64 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  72 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  79 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 102 | ERROR   | [x] Doc comment short description must end with a full stop
 114 | ERROR   | [x] Doc comment short description must end with a full stop
 159 | ERROR   | [x] Doc comment short description must end with a full stop
 171 | ERROR   | [x] Doc comment short description must end with a full stop
 184 | ERROR   | [x] Doc comment short description must end with a full stop
 196 | ERROR   | [x] Doc comment short description must end with a full stop
 206 | WARNING | [ ] Line exceeds 80 characters; contains 122 characters
 206 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 215 | ERROR   | [x] Doc comment short description must end with a full stop
 228 | ERROR   | [x] Doc comment short description must end with a full stop
 262 | ERROR   | [x] Doc comment short description must end with a full stop
 264 | ERROR   | [ ] Missing parameter comment
 293 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
 295 | ERROR   | [ ] Missing parameter comment
 295 | ERROR   | [ ] Missing parameter type
 296 | ERROR   | [x] Separate the @param and @return sections by a blank line.
 296 | ERROR   | [ ] Description for the @return value is missing
---------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 18 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Run the following command:
phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml menu_trail_by_path
๐Ÿ“Œ Task
Status

Needs review

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia Harshita mehra

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 @Harshita mehra
  • Status changed to Needs review 12 months ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 12 months ago
    9 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Harshita mehra

    I have provided a patch to fix this issue.
    Please review it.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arpitk
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arpitk

    I reviewed the patch #2. It applied cleanly and no error/warning related to phpcs Drupal are produced. How ever this issue is about fixing phpcs issues so all issues can be taken care in single issue no need to create different issues. like https://www.drupal.org/project/menu_trail_by_path/issues/3371326 ๐Ÿ“Œ Replace the t() calls to $this->t() in classes. Needs review

    Thanks!

  • Status changed to RTBC 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Priya_Degwekar

    Hi @Harshita mehna, Verified and Tested #2 ๐Ÿ“Œ Fix the issues reported by phpcs Needs work .
    It's working fine.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Priya_Degwekar

    Can be moved to RTBC.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
       /**
    +   * Template File Doc Comment.
    +   *
        * @var \Drupal\Core\Path\PathValidatorInterface
        */
    -   protected $pathValidator;
       /**
    +   * Template File Doc Comment.
    +   *
        * @var \Drupal\Core\Routing\RequestContext
        */
       protected $context;
    
       /**
    +   * Template File Doc Comment.
    +   *
        * @var \Drupal\Core\Language\LanguageManagerInterface
        */

    Those are not property descriptions. (The fact the same phrase is repeated for three different properties of the same class should suggest that phrase does not describe those properties.)

        * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
    +   *   Managing menu links and storing their definitions.
        * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
    +   *   Provides an interface for classes representing the result of routing.
        * @param \Drupal\Core\Cache\CacheBackendInterface $cache
    +   *   Defines an interface for cache implementations.
        * @param \Drupal\Core\Lock\LockBackendInterface $lock
    +   *   Lock backend interface.
        * @param \Drupal\Core\Path\PathValidatorInterface $path_validator
    +   *   Provides an interface for URL path validators.
        * @param \Drupal\Core\Routing\RequestContext $context
    +   *   Provides a fluent interface.
        * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
    +   *   Common interface for the language manager service.
        * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    +   *   Defines the interface for a configuration object factory.
    

    Those are not correct descriptions to use with parameters. I would suggest to check the parameter descriptions used for Drupal core classes. In most of the cases, there is no need to use a different description.
    For example, it is not Defines the interface for a configuration object factory. (since an object does not define an interface, but implements an interface), but The config factory.

    -   * @return \Drupal\Core\Menu\MenuLinkInterface|NULL
    -   *   The menu link for the given menu, or NULL if there is no matching menu link.
    +   * @return \Drupal\Core\Menu\MenuLinkInterface|null
    +   *   The menu linkร‚ refers to the given menu, or NULL if none exists.
        */

    The existing description is already correct.

    -   * NOTE: There is a difference between $this->routeMatch->getRouteName and $this->context->getPathInfo()
    -   * for now it seems more logical to prefer the latter, because that's the "real" url that visitors enter in their browser..
    +   * NOTE: There is a difference between:
    +   * $this->routeMatch->getRouteName and $this->context->getPathInfo()

    The period at the end is missing. NOTE must be spelled Note and the colons after Note and between must be removed.

    +   * for now it seems more logical to prefer the latter,
    +   * because that's the "real" url that visitors enter
    +   * in their browser.

    For must be capitalized and url spelled URL.

        * @return \Drupal\Core\Url|null
    +   *   A string containing a URL that may be used to access the file.

    The description must also say when NULL is returned.

       /**
    -   * Array key's should be the menu title's, if multi-level than separated by ' ร‚ยป '.
    +   * Array key's should be the menu title's.
        *
    -   * @var Url[]
    +   * If multi-level than separated by ' ร‚ยป '.
    +   *
    +   * @var \Drupal\Core\Url[]
        */
       protected $menuUrls = [];

    The description does not describe the property.

       /**
    +   * Provides an interface defining a user entity.
    +   *
        * @var \Drupal\user\UserInterface
        */
       protected $authenticatedUser;

    A property does not provide interfaces; eventually, an object implements interfaces, but that does not say what that property contains.

    -    // Create user
    +    // Create user.
         $this->authenticatedUser = $this->drupalCreateUser();

    That comment can be removed, since there is no need to explain what $this->drupalCreateUser() does; the method name explains itself.

    -    // Create content type
    -    $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
    +    // Create content type.
    +    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
     
    -    // Create nodes
    +    // Create nodes.
         $home = $this->drupalCreateNode();
         $this->createPathAlias('/node/' . $home->id(), '/home');

    The same holds true for those comments.

       /**
    -   * Test url: Home
    +   * Test url: Home.
        */
       public function testUrlHome() {
         $this->drupalGet(clone $this->menuUrls['Home']);
    @@ -111,7 +115,7 @@ class MenuTrailByPathActiveTrailHtmlClassTest extends BrowserTestBase {
       }
     
       /**
    -   * Test url: User password
    +   * Test url: User password.
        */
       public function testUrlUserPassword() {
         $this->drupalGet(clone $this->menuUrls['User password']);
    @@ -156,7 +160,7 @@ class MenuTrailByPathActiveTrailHtmlClassTest extends BrowserTestBase {
       }
     
       /**
    -   * Test url: User login
    +   * Test url: User login.

    That is the minimum required change. Test url: User login should be Test the user login URL. Similar change must be done for the other comments.

    -    // Also test the parent item, due to the tree url key construction of assertMenuActiveTrail we need two separate calls
    +    // Also test the parent item, due to the tree url key
    +    // construction of assertMenuActiveTrail we need two separate calls.

    The correct sentence is Also test the parent item; due to the tree URL key construction of assertMenuActiveTrail, we need two separate calls.

       /**
    -   * Build a menu with the data of $this->menuUrls
    +   * Build a menu with the data of $this->menuUrls.
        *
        * @param string $menu_name
    +   *   Build a menu.
        */
       protected function buildMenu($menu_name = 'main') {

    Build in the method description must be Builds.
    Build a menu is not a parameter description: A parameter does not build anything.
    The return value description is missing.

       /**
    -   * Helper for getting the base: "link_path" that assertMenuActiveTrail expects.
    +   * Helper for getting the base:"link_path" that assertMenuActiveTrail expects.

    It is the base link path that.

    +   * @param string $name
    +   *   Specifies the URL for all relative URLs in the page.

    Specifies is not necessary.

  • Assigned to imustakim
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 11 months ago
    9 pass
  • Issue was unassigned.
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad

    Addressed all the suggestion mentioned in #8 ๐Ÿ“Œ Fix the issues reported by phpcs Needs work .
    Please review the MR.

  • Status changed to RTBC 11 months ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi,

    I applied the latest MR !8 to the Menu Trail By Path module against 2.x-dev on Drupal 9.5.10 and confirmed all PHPCS errors have been fixed.

    I ran this command on the module:
    phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml menu_trail_by_path/

    Please see the attached files for reference.

    I'm moving this now to RTBC.

    Thank you!

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • First commit to issue fork.
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 11 months ago
    9 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Preethy_ray

    pray_12 โ†’ made their first commit to this issueโ€™s fork.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    9 pass
  • Status changed to Needs review 5 months ago
Production build 0.69.0 2024