Fix the errors/warnings reported by PHP_CodeSniffer

Created on 4 February 2021, almost 4 years ago
Updated 15 February 2024, 9 months ago

Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig shows the following warnings/errors, which should be fixed.

FILE: ./src/BreadcrumbItem.php
----------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
----------------------------------------------------------------------
 15 | ERROR | [ ] Missing member variable doc comment
 17 | ERROR | [x] Missing function doc comment
 19 | ERROR | [x] Missing function doc comment
 25 | ERROR | [x] Missing function doc comment
 29 | ERROR | [x] Missing function doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/ConsistentBreadcrumbBuilderInterface.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 9 | ERROR | [x] Missing interface doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/ConsistentBreadcrumbManager.php
----------------------------------------------------------------------
FOUND 16 ERRORS AND 3 WARNINGS AFFECTING 19 LINES
----------------------------------------------------------------------
  14 | WARNING | [x] Unused use statement
  17 | ERROR   | [x] Missing class doc comment
  21 | ERROR   | [ ] Missing member variable doc comment
  23 | ERROR   | [ ] Missing member variable doc comment
  25 | ERROR   | [ ] Missing member variable doc comment
  27 | ERROR   | [ ] Missing member variable doc comment
  43 | ERROR   | [x] Missing function doc comment
  50 | ERROR   | [x] Missing function doc comment
  76 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
  84 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
  98 | ERROR   | [ ] Missing parameter comment
 100 | ERROR   | [ ] Description for the @return value is missing
 122 | ERROR   | [ ] Missing parameter comment
 128 | WARNING | [ ] Line exceeds 80 characters; contains 86
     |         |     characters
 148 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
 159 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
 169 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
 208 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
 212 | ERROR   | [x] Missing function doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/ConsistentBreadcrumbManagerInterface.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 9 | ERROR | [x] Missing interface doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/ConsistentBreadcrumbs/PathBasedConsistentBreadcrumbBuilder.php
----------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 7 LINES
----------------------------------------------------------------------
 12 | ERROR | [x] Missing class doc comment
 14 | ERROR | [ ] Missing member variable doc comment
 16 | ERROR | [ ] Missing member variable doc comment
 18 | ERROR | [ ] Missing short description in doc comment
 19 | ERROR | [ ] Missing parameter comment
 25 | ERROR | [x] Missing function doc comment
 45 | ERROR | [x] Missing function doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/ConsistentBreadcrumbs/TrivialConsistentBreadcrumbBuilder.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 11 | ERROR | [x] Missing class doc comment
 13 | ERROR | [x] Missing function doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/ConsistentBreadcrumbsRoutingHelper.php
----------------------------------------------------------------------
FOUND 18 ERRORS AND 1 WARNING AFFECTING 18 LINES
----------------------------------------------------------------------
  26 | ERROR   | [x] Missing class doc comment
  28 | ERROR   | [ ] Missing member variable doc comment
  30 | ERROR   | [ ] Missing member variable doc comment
  32 | ERROR   | [ ] Missing member variable doc comment
  34 | ERROR   | [ ] Missing member variable doc comment
  36 | ERROR   | [ ] Missing member variable doc comment
  38 | ERROR   | [ ] Missing member variable doc comment
  41 | ERROR   | [x] Doc comment short description must end with a
     |         |     full stop
  48 | ERROR   | [x] Expected "string" but found "string;" for @var
     |         |     tag in member variable comment
  52 | ERROR   | [x] Missing function doc comment
  61 | ERROR   | [x] Expected 1 blank line after function; 2 found
  94 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
  98 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
 102 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
 106 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
 130 | ERROR   | [ ] Parameter $routeMatch is not described in
     |         |     comment
 135 | ERROR   | [ ] Doc comment for parameter $url does not match
     |         |     actual variable name $routeMatch
 148 | WARNING | [ ] Line exceeds 80 characters; contains 100
     |         |     characters
 148 | ERROR   | [x] Inline comments must end in full-stops,
     |         |     exclamation marks, question marks, colons, or
     |         |     closing parentheses
----------------------------------------------------------------------
PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 145ms; Memory: 10MB

 
 

๐Ÿ“Œ Task
Status

Needs review

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia vipin.mittal18 Greater Noida

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.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Assigned to thakurnishant_06
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Created the patch to fix the coding standard issues and warnings on branch 2.0.x-dev .
    Kindly review the patch.
    Thank you.

  • @thakurnishant_06 opened merge request.
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +  /**
    +   * Constructs a BreadcrumbItem object.
    +   */

    The class name is missing the namespace.

    +  /**
    +   * Creates a new BreadcrumbItem instance.
    +   *
    +   * @param \Drupal\Core\Link|null $link
    +   *   (optional) The link associated with the breadcrumb item.
    +   *
    +   * @return \Drupal\consistent_breadcrumbs\BreadcrumbItem
    +   *   The BreadcrumbItem instance.
    +   */
       public static function create(?Link $link = NULL): BreadcrumbItem {

    Since the method returns an instance of the same class, it should be @return static.

    +   * @return $this
    +   *   The current BreadcrumbItem object.
    +   */
       public function setLink(?Link $link): self {

    Since it uses @return $this, the return value description is not necessary.

    +/**
    + * Defines the interface for Consistent Breadcrumb builders.
    + */
     interface ConsistentBreadcrumbBuilderInterface {

    Saying that an interface defines the interface for Consistent Breadcrumb builders is not giving a useful description.

    +/**
    + * Manages the consistent breadcrumb generation.
    + */
     class ConsistentBreadcrumbManager implements ConsistentBreadcrumbManagerInterface {

    What is a consistent breadcrumb generation? It is better to say Provides a manager for [โ€ฆ]. or Manages discovery and instantiation of [โ€ฆ] plugins. which are two of the descriptions used by Drupal core for plugin managers.

    +  /**
    +   * The static cache backend.
    +   *
    +   * @var \Drupal\Core\Cache\CacheBackendInterface
    +   */
       private CacheBackendInterface $staticCache;

    It is sufficient to say The cache backend.

    +  /**
    +   * The primary breadcrumb builder.
    +   *
    +   * @var \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface
    +   */
       private BreadcrumbBuilderInterface $breadcrumbManager;

    The breadcrumb builder. is sufficient.

    +  /**
    +   * Constructs a ConsistentBreadcrumbManager object.
    +   *
    +   * @param \Drupal\Core\Cache\CacheBackendInterface $staticCache
    +   *   The static cache backend.
    +   * @param \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface $breadcrumbManager
    +   *   The primary breadcrumb builder.
    +   * @param \Drupal\consistent_breadcrumbs\ConsistentBreadcrumbsRoutingHelper $routingHelper
    +   *   The routing helper.
    +   * @param \Drupal\Core\Http\RequestStack $requestStack
    +   *   The request stack.
    +   */

    The class namespace is missing.

       /**
    -   * @inheritDoc
    +   * {@inheritDoc}
        */

    It is {@inheritdoc}.

  • Assigned to thakurnishant_06
  • Thanks for the review!!
    I will work on this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Bhupesh_upadhyay

    Phpcs fixed,
    kindly review.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -  private function __construct() {}
    -

    The constructor has been declared private to avoid it is used to create an instance of that class. It cannot be removed, or PHP will assign to the class a public constructor.

    +   * @return static \Drupal\consistent_breadcrumbs\BreadcrumbItem
    +   *   The BreadcrumbItem instance.

    When static or $this are used as return type, there is no need to also add the class name. I think in Drupal $this is used instead of static, though.

    +/**
    + * Provides an interface defining a Consistent Breadcrumb builders.
    + */
     interface ConsistentBreadcrumbBuilderInterface {

    An interface that provides an interface is quiteโ€ฆ tautological, especially when the description ends with the interface name.

    +/**
    + * Manages the consistent breadcrumb generation.
    + */
     class ConsistentBreadcrumbManager implements ConsistentBreadcrumbManagerInterface {

    The description should be a little better than that.

    +  /**
    +   * Constructs a ConsistentBreadcrumbManager object.
    +   *

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

       /**
    -   * @inheritDoc
    +   * {@inheritDoc}.

    The period is not added after {@inheritdoc}. It is {@inheritdoc}, not {@inheritDoc}.

    -        // dump(__FUNCTION__ . ':noLink');
    +        // dump(__FUNCTION__ . ':noLink');.

    Periods are not added to commented out code.

    +/**
    + * Defines the interface for the Consistent Breadcrumb Manager.
    + */

    Interface descriptions must not start with Defines.

    +/**
    + * Path-based Consistent Breadcrumb builder implementation.
    + */

    implementation is never used in class descriptions, in Drupal core.

    +   * @return string
    +   *   The front page path.
    +   */
       private function getFrontPagePath() {

    The method returns also NULL.

  • Hi,
    Applied #11 patch , the patch is not get applied and throwing error.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Merge request !2Resolve #3196460 "2.0.x" โ†’ (Open) created by apaderno
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    apaderno โ†’ changed the visibility of the branch 3196460-FIX-PHPCS-ISSUES to hidden.

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

    apaderno โ†’ changed the visibility of the branch 2.0.x to hidden.

Production build 0.71.5 2024