Fix the issues reported by phpcs

Created on 22 February 2023, almost 2 years ago
Updated 14 February 2024, 10 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: ./advpoll.install
----------------------------------------------------------------------
FOUND 7 ERRORS AND 4 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------
  1 | ERROR   | [x] Missing file doc comment
  7 | 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."
  7 | ERROR   | [x] Doc comment short description must start with a
    |         |     capital letter
  7 | ERROR   | [x] Doc comment short description must end with a
    |         |     full stop
 10 | ERROR   | [x] Inline comments must start with a capital letter
 42 | 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."
 42 | ERROR   | [x] Doc comment short description must start with a
    |         |     capital letter
 42 | ERROR   | [x] Doc comment short description must end with a
    |         |     full stop
 45 | ERROR   | [x] Inline comments must start with a capital letter
 71 | WARNING | [ ] Unused variable $entity.
 84 | WARNING | [ ] Unused variable $entity.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./advpoll.module
----------------------------------------------------------------------
FOUND 5 ERRORS AND 11 WARNINGS AFFECTING 13 LINES
----------------------------------------------------------------------
  1 | ERROR   | [x] Missing file doc comment
 11 | WARNING | [ ] Line exceeds 80 characters; contains 111
    |         |     characters
 12 | WARNING | [ ] Line exceeds 80 characters; contains 113
    |         |     characters
 12 | ERROR   | [x] Inline comments must end in full-stops,
    |         |     exclamation marks, question marks, colons, or
    |         |     closing parentheses
 29 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: 'content'
 36 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: TRUE
 38 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: 'content'
 45 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: TRUE
 47 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: 'content'
 53 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: 'content'
 59 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: 'content'
 68 | WARNING | [ ] Line exceeds 80 characters; contains 101
    |         |     characters
 68 | ERROR   | [x] Inline comments must start with a capital letter
 68 | ERROR   | [x] Inline comments must end in full-stops,
    |         |     exclamation marks, question marks, colons, or
    |         |     closing parentheses
 70 | ERROR   | [x] Short array syntax must be used to define arrays
 92 | WARNING | [ ] Unused variable $poll.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: .../kiamlaluno/SSDPR/Patches/advpoll/src/AdvPollPostRenderCache.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 3 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------
 10 | ERROR   | [ ] Doc comment short description must be on a single
    |         |     line, further text should be a separate paragraph
 32 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
 60 | WARNING | [ ] \Drupal calls should be avoided in classes, use
    |         |     dependency injection instead
 62 | WARNING | [ ] \Drupal calls should be avoided in classes, use
    |         |     dependency injection instead
 62 | WARNING | [ ] \Drupal calls should be avoided in classes, use
    |         |     dependency injection instead
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...amlaluno/SSDPR/Patches/advpoll/src/Form/ApprovalPollViewForm.php
----------------------------------------------------------------------
FOUND 16 ERRORS AND 1 WARNING AFFECTING 15 LINES
----------------------------------------------------------------------
   6 | ERROR   | [x] Use statements should be sorted alphabetically.
     |         |     The first wrong one is
     |         |     Drupal\Core\Form\BaseFormIdInterface.
  12 | ERROR   | [x] Doc comment short description must end with a
     |         |     full stop
  15 | WARNING | [ ] The class short comment should describe what the
     |         |     class does and not simply repeat the class name
  21 | ERROR   | [ ] Class constants must be uppercase; expected
     |         |     WRITEININDEX but found writeInIndex
 226 | ERROR   | [x] Short array syntax must be used to define arrays
 242 | ERROR   | [ ] Missing parameter comment
 243 | ERROR   | [ ] Missing parameter comment
 255 | ERROR   | [x] Expected 1 space after FOREACH keyword; 0 found
 333 | ERROR   | [ ] Description for the @return value is missing
 347 | ERROR   | [ ] Missing parameter comment
 347 | ERROR   | [x] Expected 1 spaces after parameter type; 2 found
 347 | ERROR   | [x] Tag value indented incorrectly; expected 1 space
     |         |     but found 2
 349 | ERROR   | [ ] Description for the @return value is missing
 367 | ERROR   | [ ] Description for the @return value is missing
 387 | ERROR   | [x] Short array syntax must be used to define arrays
 397 | ERROR   | [x] Expected 1 blank line after function; 0 found
 398 | ERROR   | [x] The closing brace for the class must have an
     |         |     empty line before it
----------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 129ms; Memory: 12MB
📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇮🇳India TanujJain-TJ

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 @TanujJain-TJ
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India TanujJain-TJ

    Fixed above mentioned phpcs errors in this patch, ignoring .yml file phpcs issues for following errors.

    FILE: /advpoll/advpoll.info.yml
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | WARNING | Remove "project" from the info file, it will be added by
       |         | drupal.org packaging automatically
     1 | WARNING | Remove "datestamp" from the info file, it will be added by
       |         | drupal.org packaging automatically
     1 | WARNING | Remove "version" from the info file, it will be added by
       |         | drupal.org packaging automatically
    -------------------------------------------------------------------------------

    Please review.

  • 🇮🇳India sahil.goyal

    @TanujJain-TJ Thanx for the updated patch, but still there are unused variables. so updating the patch with interdiff.

  • Status changed to Needs work almost 2 years ago
  • 🇮🇳India saket-001

    applying patch #2 still the issue is there so i changing status to need work.

  • First commit to issue fork.
  • Assigned to vishaljd
  • @vishaljd opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India nayana_mvr

    Verified MR!9 on Drupal version 9.5.x and Advanced Poll version 8.x - 1.x. Patch applied cleanly but errors in advpoll.install and advpoll.module are not there in the MR. So its showing the follwing errors even after applying the patch:

    FILE: ../contrib/advpoll/advpoll.install
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 7 ERRORS AND 4 WARNINGS AFFECTING 7 LINES
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
      1 | ERROR   | [x] Missing file doc comment
      7 | 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."
      7 | ERROR   | [x] Doc comment short description must start with a capital letter
      7 | ERROR   | [x] Doc comment short description must end with a full stop
     10 | ERROR   | [x] Inline comments must start with a capital letter
     42 | 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."
     42 | ERROR   | [x] Doc comment short description must start with a capital letter
     42 | ERROR   | [x] Doc comment short description must end with a full stop
     45 | ERROR   | [x] Inline comments must start with a capital letter
     71 | WARNING | [ ] Unused variable $entity.
     84 | WARNING | [ ] Unused variable $entity.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: ../contrib/advpoll/advpoll.module
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 5 ERRORS AND 11 WARNINGS AFFECTING 13 LINES
    ------------------------------------------------------------------------------------------------------------------------------
      1 | ERROR   | [x] Missing file doc comment
     11 | WARNING | [ ] Line exceeds 80 characters; contains 111 characters
     12 | WARNING | [ ] Line exceeds 80 characters; contains 113 characters
     12 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
     29 | WARNING | [x] A comma should follow the last multiline array item. Found: 'content'
     36 | WARNING | [x] A comma should follow the last multiline array item. Found: TRUE
     38 | WARNING | [x] A comma should follow the last multiline array item. Found: 'content'
     45 | WARNING | [x] A comma should follow the last multiline array item. Found: TRUE
     47 | WARNING | [x] A comma should follow the last multiline array item. Found: 'content'
     53 | WARNING | [x] A comma should follow the last multiline array item. Found: 'content'
     59 | WARNING | [x] A comma should follow the last multiline array item. Found: 'content'
     68 | WARNING | [ ] Line exceeds 80 characters; contains 101 characters
     68 | ERROR   | [x] Inline comments must start with a capital letter
     68 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
     70 | ERROR   | [x] Short array syntax must be used to define arrays
     92 | WARNING | [ ] Unused variable $poll.
    ------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------
    
    Time: 268ms; Memory: 12MB
    
  • 🇮🇳India nayana_mvr

    Created a new MR!10 fixing all the errors mentioned in the ticket.
    @vishaljd I can see that in the MR!9, there are some changes in advpoll.services.ymlbut I couldn't find any error in that file before applying the patch so I have excluded that change in the new MR.

    Please review. Thanks.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to RTBC over 1 year ago
  • 🇵🇭Philippines paraderojether

    Hi nayana_mvr,

    I reviewed MR!10 and confirmed it fixes all the errors and warnings reported by phpcs. Drupal core version 9.58, Advanced Poll 8.x-1.x-dev.

    I added screenshots for reference.
    Thank You.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * The class Resolver.
    +   *

    Only the first word in the description must be capitalized.

    +  /**
    +   * The request stack services.
    +   *
    +   * @var \Symfony\Component\HttpFoundation\RequestStack
    +   */
    +  protected $requestStack;

    It would be The request stack service. but The request stack. is sufficient.

       /**
        * Constructs a new PollPostRenderCache object.
        *

    Since that class is inside the AdvPollPostRenderCache.php file, the class cannot be PollPostRenderCache.
    The constructor description is also missing the class namespace.

       /**
    -   * @inheritDoc
    +   * Trusted Call backs.
        */
       public static function trustedCallbacks() {

    Method inherited from a parent class or defined by an interface are simply documented with {@inheritdoc}.

        * @return int
    +   *   A integer containing a number of max choice.

    It is not necessary to add the return type in the description, since that is already made clear from the previous line.

        * @return array
    +   *   A array containing a form option value.

    * @return int
    + * A integer containing a time stamps of poll.

    It is An array and An integer, but it is not necessary to repeat the return value type.

  • Assigned to imustakim
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada imustakim Canada

    Patch added.
    Please review.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    --- a/advpoll.install
    +++ b/advpoll.install
    @@ -1,13 +1,18 @@
     <?php
     
    +/**
    + * @file
    + * Contains install and update functions for Advanced Poll.
    + */
    +

    The correct description is Install, update, and uninstall hooks for the Advanced Poll module.

    --- a/advpoll.module
    +++ b/advpoll.module
    @@ -1,5 +1,10 @@
     <?php
     
    +/**
    + * @file
    + * This module extends Drupal Poll to provide additional poll types.
    + */
    +

    The correct description is Hook implementations for the Advanced Poll module.

     function advpoll_form_poll_edit_form_alter(&$form, FormStateInterface $form_state) {
       /** @var \Drupal\poll\Entity\Poll $poll */
    -  $poll = $form_state->getFormObject()->getEntity();
    -
    +  // $poll = $form_state->getFormObject()->getEntity();

    If a code line is not necessary, it is removed, not commented out.

    - * Class ApprovalPollViewForm
    + * Defines a class Approval Poll View Form.
      *
      * @package Drupal\advpoll\Form
      */

    Only the first word in the description must be capitalized.
    Also, for a class, Defines a class is not correct.

        * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   The form state interface.

    It is simply The form state.

    -   * @param  \Drupal\Core\Form\FormStateInterface  $form_state
    +   * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   The form state interfece.

    There is a typo in interfece, but The form state. is sufficient.

        * @return int
    +   *   The timestamps of poll.
        */
       protected function getStartTimestamp() {

    It is The poll timestamp.

  • Assigned to imustakim
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada imustakim Canada

    Patch updated.
    Please review.

  • I reviewed patch #20 , applied cleanly. it fixes all the errors and warnings reported by phpcs and addresses the comments in #18 .

  • Status changed to Needs work 11 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Since it has been already created, let's continue with MR !10, which still needs work.

    The issue summary must be updated: I get more warnings/errors when I run PHP_CodeSniffer.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • First commit to issue fork.
  • Status changed to Needs review 10 months ago
  • 🇮🇳India pray_12

    Hi,
    Reviewed the MR!10[#24] found no Phpcs errors and warnings.
    Thank you!!

Production build 0.71.5 2024