Fix the issues reported by phpcs

Created on 27 June 2023, over 1 year ago
Updated 23 August 2023, over 1 year ago

Problem/Motivation

There are some Drupal coding standard errors which needs to to be fixed.

Steps to reproduce

Run phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/contrib/aidev

FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\aidev.module
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | ERROR | [x] Missing file doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\aidev.services.yml
---------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------
 4 | ERROR | [x] Expected 1 newline at end of file; 0 found
---------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------
FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\aidev.info.yml
-----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------
 4 | ERROR | [x] Expected 1 newline at end of file; 0 found
-----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------
FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\src\Source.php
--------------------------------------------------------------------------------
FOUND 9 ERRORS AND 4 WARNINGS AFFECTING 13 LINES
--------------------------------------------------------------------------------
   7 | ERROR   | [x] There must be one blank line after the last USE statement;
     |         |     2 found;
  65 | ERROR   | [x] Whitespace found at end of line
  70 | ERROR   | [ ] Expected type hint "string"; found "array" for
     |         |     $include_files
  93 | WARNING | [ ] Line exceeds 80 characters; contains 106 characters
 107 | WARNING | [x] A comma should follow the last multiline array item.
     |         |     Found: $file_contents
 113 | ERROR   | [x] Expected 1 blank line after function; 2 found
 127 | ERROR   | [ ] Expected type hint "SplFileInfo"; found "\SplFileInfo" for
     |         |     $file
 140 | ERROR   | [x] Expected newline after closing brace
 141 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
 150 | ERROR   | [x] Expected 1 blank line after function; 2 found
 162 | WARNING | [ ] Line exceeds 80 characters; contains 126 characters
 180 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL"
     |         |     but found "null"
 183 | ERROR   | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\src\SourceInterface.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 27 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\src\Exception\InvalidProjectException.php
--------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Missing class doc comment
 6 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------
FILE: C:\xamppnew\htdocs\sonam\web\modules\contrib\aidev\tests\src\Unit\SourceTest.php
--------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------------
 30 | ERROR | [x] Missing function doc comment
 38 | ERROR | [x] Expected 1 blank line after function; 2 found
 69 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------
📌 Task
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

🇮🇳India sonam_sharma

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 @sonam_sharma
  • Status changed to Needs work over 1 year ago
  • 🇱🇹Lithuania mindaugasd

    1. Patch contains incorrect line, which would introduce bug

    [ ] Expected type hint "string"; found "array" for $include_files

    The docblock has incorrect info which should be changed instead

    @param string $include_files

    2. Another line which might be incorrect, and might introduce bug as well

    [ ] Expected type hint "SplFileInfo"; found "\SplFileInfo" for $file

    I will change patch, test and commit at some point.

  • 🇮🇳India sonam_sharma

    hello,
    I have fixed
    1. Patch contains incorrect line, which would introduce bug

    [ ] Expected type hint "string"; found "array" for $include_files

    The docblock has incorrect info which should be changed instead

    @param string $include_files

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • Hello @sonam_sharma,
    Applied your patch . Still many coding standard issues needs to be fixed.

    FILE: /opt/lampp/htdocs/commerce_addons/web/modules/contrib/aidev/PATCHES.txt
    -----------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    -----------------------------------------------------------------------------
     1 | WARNING | [ ] Line exceeds 80 characters; contains 104 characters
     5 | ERROR   | [x] Expected 1 newline at end of file; 3 found
    -----------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------
    
    
    FILE: /opt/lampp/htdocs/commerce_addons/web/modules/contrib/aidev/src/Source.php
    ----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\aidev\Exception\InvalidProjectException.
    ----------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /opt/lampp/htdocs/commerce_addons/web/modules/contrib/aidev/README.md
    ---------------------------------------------------------------------------
    FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
    ---------------------------------------------------------------------------
     33 | WARNING | Line exceeds 80 characters; contains 165 characters
     39 | WARNING | Line exceeds 80 characters; contains 88 characters
     40 | WARNING | Line exceeds 80 characters; contains 117 characters
     41 | WARNING | Line exceeds 80 characters; contains 118 characters
     43 | WARNING | Line exceeds 80 characters; contains 106 characters
     46 | WARNING | Line exceeds 80 characters; contains 102 characters
    ---------------------------------------------------------------------------
    
    
    FILE: /opt/lampp/htdocs/commerce_addons/web/modules/contrib/aidev/tests/src/Unit/SourceTest.php
    -----------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 5 LINES
    -----------------------------------------------------------------------------------------------
     30 | ERROR   | [x] Missing function doc comment
     38 | ERROR   | [x] Expected 1 blank line after function; 2 found
     52 | WARNING | [ ] Unused variable $source_code.
     66 | WARNING | [ ] Unused variable $source_code.
     69 | ERROR   | [x] Expected 1 newline at end of file; 0 found
    -----------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------
    
    

    Thankyou.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India sonam_sharma

    I have fixed both the remaining issues:-
    1. Patch contains incorrect line, which would introduce bug

    [ ] Expected type hint "string"; found "array" for $include_files

    The docblock has incorrect info which should be changed instead

    @param string $include_files

    2. Another line which might be incorrect, and might introduce bug as well

    [ ] Expected type hint "SplFileInfo"; found "\SplFileInfo" for $file
    please! review the patch

  • Status changed to Needs work over 1 year ago
  • Hello @sonam_sharma.
    The patch was applied smoothly but still there are few issues left (addressed in #6). Moving it to needs work.
    Adding screenshot for reference.
    Thank You.

  • 🇱🇹Lithuania mindaugasd

    Also why comments are split with a . (dot) or each line starts with Uppercase letter?
    It breaks English grammar and readability.
    Is that a coding standard, or a bug?
    Since it is not consistent (once it starts with an upper letter, other times is not) then I think these comments are incorrect in the patch.

  • 🇮🇳India sonam_sharma

    hello @ mindaugasd
    I have removed dots & Uppercases from splitting lines

  • 🇮🇳India sonam_sharma

    hello,
    @thakurnishant_06
    I have fixed remaining issues
    please! review the new_phpcs_3370530.patch

  • Assigned to thakurnishant_06
  • Hello @sonam_sharma,
    Tested new_phpcs_3370530.patch . Patch applied smoothly . Some errors are still there addressed in #8.

    I will work on this.
    Thank you.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Adding a updated patch to fix all remaining warnings and errors (addressed in #8), related to Drupal coding standard.
    Kindly review the patch.
    Thank you for your support.

  • @sonam_sharma opened merge request.
  • 🇱🇹Lithuania mindaugasd

    @sonam_sharma your merge request is empty, has no changes

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +/**
    + * @file
    + * Contains the AI developer assistant module.
    + */

    The usual description is Hook implementations for the [module name] module. where [module name] is the module name shown in the .info.yml file.

    +/**
    + * Represents an exception for invalid projects.
    + *
    + * @package Drupal\aidev
    + */
     class InvalidProjectException extends \Exception {

    Class descriptions must not start with Represent/Represents. Exception thrown when […]. is a better description.

    -      // If the current file is a regular file, read its contents and store them in the associative array.
    +      // If the current file is a regular file, read its contents and
    +      // store them in the associative array.

    It is file content, not file contents. This means the phrase must be read its content and store it in an array.

    +      else {
    +        // Check if $exclusion appears in the file path and is a separate path
    +        // (i.e., right after a path separator, before a separator, or both).
    +        // If it does, return TRUE.
             if (preg_match('~(^|/)' . preg_quote($exclusion, '~') . '(/|$)~', $file_path)) {
               return TRUE;
             }

    I would remove If it does, return TRUE. as that part of the code does not need explanations.

    +  /**
    +   * Sets up the test environment.
    +   *
    +   * @return void
    +   *   Nothing is returned by this method.
    +   */
       protected function setUp(): void {

    Since that is an inherited method, its documentation comment just needs to contain @{inheritdoc}.

  • Assigned to Anjali Mehta
  • 🇮🇳India Anjali Mehta

    I will work on this
    Thank You.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Anjali Mehta

    Hello Everyone,
    Created a patch to update the changes addressed in #16.
    Kindly review the patch.
    Thank you for support.

  • Status changed to RTBC over 1 year ago
  • Hello @Anjali Mehta,
    Tested your patch . Patch applied smoothly . Patch updated all the changes addressed in #16.
    can be moved to RTBC.
    Thank you for your support.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Patches need to include all the changes, not just the changes required in the last review.
    The other patches size is between 5 KB and 6 KB. The last patch size is just 2.01 KB.

  • Assigned to Prachi6824
  • 🇮🇳India Prachi6824

    Let me work on this issue and try to solve it .

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Prachi6824

    Hello,

    I have created a patch to solve all the errors related to phpcs code standard issues .
    Also, for the phpcs Drupal practice issues.

    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------
    54 | WARNING | Unused variable $source_code.
    68 | WARNING | Unused variable $source_code.
    ---------------------------------------------------------------------------------

    Please review my patch and apply it .
    Thank You.

  • Status changed to Closed: won't fix over 1 year ago
  • 🇱🇹Lithuania mindaugasd

    I am not commiting, because:

    Thank you @apaderno for reviewing patches.

Production build 0.71.5 2024