Fix the errors/warnings reported by PHP_CodeSniffer

Created on 17 October 2023, 9 months ago
Updated 25 October 2023, 8 months ago

Problem/Motivation

Handle the following errors.
FILE: /rest_password.module
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 | ERROR | [x] There must be exactly one blank line after the file comment
156 | ERROR | [x] Use null coalesce operator instead of ternary operator.
222 | WARNING | [ ] Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.", "* Implements
| | hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
223 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
234 | ERROR | [x] Short array syntax must be used to define arrays
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /rest_password.services.yml
-----------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------
5 | ERROR | [x] Expected 1 newline at end of file; 2 found
-----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------

FILE: /src/Plugin/rest/resource/GetPasswordRestResource.php
-------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------
40 | ERROR | Parameter $user_storage is not described in comment
-------------------------------------------------------------------------------------------------------------------------

FILE: /src/Controller/UserAuthenticationTempPassController.php
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
---------------------------------------------------------------------------------------------------------------------------------------
107 | ERROR | Parameter $shared_temp_store is not described in comment
126 | ERROR | Missing parameter name
322 | ERROR | The array declaration extends to column 161 (the limit is 80). The array content should be split up over multiple lines
448 | ERROR | The array declaration extends to column 89 (the limit is 80). The array content should be split up over multiple lines
---------------------------------------------------------------------------------------------------------------------------------------

FILE: /src/Controller/ResendController.php
---------------------------------------------------------------------------------------------------------------------
FOUND 7 ERRORS AND 1 WARNING AFFECTING 8 LINES
---------------------------------------------------------------------------------------------------------------------
13 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
16 | ERROR | [ ] Missing member variable doc comment
18 | ERROR | [x] Missing function doc comment
22 | ERROR | [x] Missing function doc comment
28 | ERROR | [x] Missing function doc comment
34 | ERROR | [x] Expected newline after closing brace
40 | ERROR | [x] Expected 1 blank line after function; 0 found
41 | ERROR | [x] The closing brace for the class must have an empty line before it
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Needs review

Version

8.1

Component

Code

Created by

🇮🇳India anmolgoyal74

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 @anmolgoyal74
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review 8 months ago
  • 🇮🇳India Keshav Patel

    The provided patch file "fix_coding_standards-3394540-4.patch", fixes the --standard=Drupal,DrupalPractice issues reported by phpcs.

  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    - * Class ResendController.
    + * Implements ResendController Class.

    Adding Implements does not change the fact the description is merely repeating the class name. That comment also became not correct, as a class does not implement itself.

    +  /**
    +   * Implements MessengerInterface.
    +   *
    +   * @var Drupal\Core\Messenger\MessengerInterface
    +   */
       protected $messenger;

    A property description must describe what the property is, not which interfaces it implements, which is information already given in the @var line.

    +  /**
    +   * Construct a new ResendController object.
    +   */
       public function __construct(MessengerInterface $messenger) {
         $this->messenger = $messenger;
       }

    The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace. The parameter descriptions must be included too.

    -        $this->logger->notice('Password reset instructions mailed to %name at %email.', ['%name' => $account->getAccountName(), '%email' => $account->getEmail()]);
    +        $this->logger->notice('Password reset instructions mailed to %name at %email.',
    +         [
    +           '%name' => $account->getAccountName(),
    +           '%email' => $account->getEmail(),
    +         ]);

    Code lines can exceed the 80 characters, if they are easier to understand. The existing code is easier to understand.

    +   * @param \Drupal\user\UserStorageInterface $user_storage
    +   *   User storage.

    The description is missing a definite article.

  • Status changed to Needs review 8 months ago
  • 🇮🇳India Keshav Patel

    Revised the Patch "fix_coding_standards-3394540-4.patch" as per Comment #5. The patch file "fix_coding_standards-3394540-6.patch" fixes the issues reported by phpcs in accordance with Comment #5.

  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * Provides access to the Messenger service for displaying messages.
    +   *
    +   * @var Drupal\Core\Messenger\MessengerInterface
    +   */
       protected $messenger;

    The messenger. is sufficient as description.

    +   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
    +   *   The messenger service.

    It is not necessary to say it is a service.

    +  /**
    +   * Implements resend().
    +   */

    That description is merely repeating the method name.
    The parameter descriptions and the return value description are missing.

    +   * @param \Drupal\user\UserStorageInterface $user_storage
    +   *   A User storage.

    User does not need to be capitalized. The descriptions start with a definite article.

    Since there is a 9.x branch, that is probably the branch that should be changed. At least, that should be the first branch to be changed and, eventually, the changes back-ported to the other branch.

  • Assigned to imustakim
  • 🇮🇳India imustakim Ahmedabad
  • @imustakim opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review 8 months ago
  • 🇮🇳India imustakim Ahmedabad

    MR Updated.
    Please review.

  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Assigned to imustakim
  • 🇮🇳India imustakim Ahmedabad
  • Issue was unassigned.
  • Status changed to Needs review 8 months ago
  • 🇮🇳India imustakim Ahmedabad

    MR Updated for review.

Production build 0.69.0 2024