Fix the issues reported by phpcs

Created on 4 May 2023, over 1 year ago
Updated 31 May 2024, 6 months ago

Problem/Motivation

Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig for the 8.x-1.x branch of this module returns the following report.

FILE: ...ers/studenttrainees/New/drupalorgsite/docroot/modules/contrib/watchdog_slack/watchdog_slack.links.task.yml
----------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/watchdog_slack/src/Form/SettingsForm.php
----------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 1 WARNING AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------------
  3 | ERROR   | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
  6 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate
    |         |     paragraph
 21 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class
    |         |     name
 41 | ERROR   | [x] Missing function doc comment
----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/watchdog_slack/src/Logger/SlackLog.php
----------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
----------------------------------------------------------------------------------------------------------------
   3 | ERROR   | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
  65 | ERROR   | [ ] Parameter $state is not described in comment
  98 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or
     |         |     closing parentheses
 123 | WARNING | [ ] Only string literals should be passed to t() where possible
 151 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate
     |         |     paragraph
----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------

Time: 301ms; Memory: 10MB

Proposed resolution

Those errors/warnings need to be fixed.

📌 Task
Status

RTBC

Version

1.0

Component

Code

Created by

🇵🇭Philippines paraderojether

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 @paraderojether
  • @paraderojether opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇵🇭Philippines paraderojether

    Created an MR to fix the issue reported by phpcs.

    Please review.
    Thank You.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
     /**
      * @file
      * Contains Drupal\watchdog_slack\Form\SettingsForm.
    + *
      * Configures administrative settings for Watchdog to slack.
      */

    That comment is not used for files containing a class.

     /**
    - * Class SettingsForm.
    + * Provides a form for configuring admin settings for Watchdog Slack module.
      *
      * @package Drupal\watchdog_slack\Form
      *
    @@ -38,6 +39,17 @@ class SettingsForm extends ConfigFormBase {

    The short description is missing an article before Watchdog Slack module.

    +  /**
    +   * Builds the form for configuring admin settings for Watchdog Slack module.
    +   *
    +   * @param array $form
    +   *   An associative array containing the structure of the form.
    +   * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   The current state of the form.
    +   *
    +   * @return array
    +   *   The form array structure.
    +   */
       public function buildForm(array $form, FormStateInterface $form_state) {

    The documentation comment for inherited methods or methods defined in an interface simply contain {@inheritdoc}.

             // Build log message.
    -        $watchdog_message = (string) $this->t($message, $message_placeholders);
    -        $watchdog_message = strip_tags($watchdog_message);
    +        $translated_message = ($message);
    +        $watchdog_message = strip_tags(strtr($translated_message, $message_placeholders));

    The existing code and the changed code are not equivalent. The changed code is not correct.

       /**
        * Increment the count of messages sent this minute.
    +   *
        * If it's a new minute of the hour, reset the counter.

    Since that documentation comment is edited, also the short description needs to be edited. The verb needs to use the third person singular.
    messages sent this minute is also not correct.

  • First commit to issue fork.
  • First commit to issue fork.
  • First commit to issue fork.
  • Status changed to Needs review 10 months ago
  • 🇮🇳India zkhan.aamir

    Hi,

    MR #2 applied successfully.
    All the issues been resolved.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib/watchdog_slack (8.x-1.x)
    $ curl https://git.drupalcode.org/project/watchdog_slack/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  3980    0  3980    0     0   9288      0 --:--:-- --:--:-- --:--:--  9320
    patching file src/Form/SettingsForm.php
    patching file src/Logger/SlackLog.php
    patching file watchdog_slack.links.task.yml
    
    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib/watchdog_slack (8.x-1.x)
    $ cd ../
    
    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib
    $ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml watchdog_slack/
    
    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib
    $
    
  • Status changed to RTBC 6 months ago
  • 🇮🇳India manish-31

    MR patch from Merge request !2 applies successfully and resolves all the PHPCS warnings. Attaching the screenshots for the same.

    RTBC +1

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    apaderno → changed the visibility of the branch 8.x-1.x-patch-dc54 to hidden.

  • Pipeline finished with Failed
    6 months ago
    Total: 43s
    #187382
Production build 0.71.5 2024