Fix the issues reported by phpcs

Created on 20 June 2023, over 1 year ago
Updated 11 July 2023, over 1 year ago

Problem/Motivation

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/ct_expire/ct_expire.module
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 45 ERRORS AND 6 WARNINGS AFFECTING 42 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13 | WARNING | [x] Unused use statement
15 | ERROR | [x] There must be one blank line after the last USE statement; 2 found;
21 | ERROR | [ ] Invalid function name, expected _y_ou_r_m_od_ul_e_node_update but found _YOUR_MODULE_node_update
21 | ERROR | [ ] All functions defined in a module file must be prefixed with the module's name, found "_YOUR_MODULE_node_update" but expected "ct_expire__YOUR_MODULE_node_update"
21 | ERROR | [x] Expected 1 blank line before function; 2 found
21 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
22 | ERROR | [x] There must not be a newline before the closing parenthesis of a single-line function declaration
23 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
24 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
31 | ERROR | [x] Opening brace should be on the same line as the declaration
32 | WARNING | [x] 'TODO: Also create drush command for this.' should match the format '@todo Fix problem X here.'
32 | WARNING | [x] There must be no blank line following an inline comment
32 | WARNING | [ ] There must be no blank line following an inline comment
32 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
34 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
34 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
35 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
36 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
38 | WARNING | [x] 'TODO: Improve performance by bundling these actions.' should match the format '@todo Fix problem X here.'
38 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
39 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
40 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
41 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
42 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
43 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
44 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
51 | ERROR | [x] Opening brace should be on the same line as the declaration
52 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
53 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
54 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
56 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
57 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
58 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
59 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
61 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
62 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
63 | ERROR | [x] Line indented incorrectly; expected 10 spaces, found 20
64 | ERROR | [x] Line indented incorrectly; expected 12 spaces, found 24
65 | ERROR | [x] Line indented incorrectly; expected 10 spaces, found 20
65 | ERROR | [x] Expected newline after closing brace
66 | ERROR | [x] Line indented incorrectly; expected 12 spaces, found 24
67 | ERROR | [x] Line indented incorrectly; expected 12 spaces, found 24
68 | ERROR | [x] Line indented incorrectly; expected 10 spaces, found 20
70 | ERROR | [x] Line indented incorrectly; expected 10 spaces, found 20
71 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
73 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
74 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
75 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
80 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
81 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
82 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 48 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/ct_expire/README.md
--------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
--------------------------------------------------------------------------------------------
8 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
10 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
16 | WARNING | [ ] Line exceeds 80 characters; contains 96 characters
26 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/ct_expire/ct_expire.install
----------------------------------------------------------------------------------------------------
FOUND 26 ERRORS AFFECTING 22 LINES
----------------------------------------------------------------------------------------------------
17 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
21 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
22 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
23 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
23 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
24 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
25 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
28 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
29 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
30 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
30 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
31 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
32 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
35 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
36 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
36 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
37 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
38 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
41 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
42 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
42 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
43 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
44 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
49 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
50 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
55 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 26 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/ct_expire/src/CtExpireScheduler.php
------------------------------------------------------------------------------------------------------------------------------
FOUND 99 ERRORS AND 9 WARNINGS AFFECTING 82 LINES
------------------------------------------------------------------------------------------------------------------------------
10 | ERROR | [x] Function comment short description must start with exactly one space
10 | ERROR | [x] Doc comment short description must end with a full stop
13 | ERROR | [x] Opening brace should be on the same line as the declaration
15 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
20 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
22 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
27 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
29 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
34 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
36 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
36 | ERROR | [ ] Missing short description in doc comment
37 | ERROR | [ ] Missing parameter comment
38 | ERROR | [ ] Missing parameter comment
39 | ERROR | [ ] Missing parameter comment
41 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
42 | ERROR | [x] Opening brace should be on the same line as the declaration
43 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
44 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
45 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
46 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
48 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
48 | ERROR | [ ] Missing short description in doc comment
49 | ERROR | [ ] Missing parameter comment
50 | ERROR | [ ] Missing parameter comment
51 | ERROR | [ ] Missing parameter comment
53 | ERROR | [ ] Description for the @return value is missing
55 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
56 | ERROR | [x] Opening brace should be on the same line as the declaration
57 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
58 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
59 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
60 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
61 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
63 | WARNING | [x] 'TODO: Do not schedule if timestamp is in the past?' should match the format '@todo Fix problem X here.'
63 | WARNING | [x] There must be no blank line following an inline comment
63 | WARNING | [ ] There must be no blank line following an inline comment
63 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
65 | WARNING | [x] 'TODO: Validate tag?' should match the format '@todo Fix problem X here.'
65 | WARNING | [x] There must be no blank line following an inline comment
65 | WARNING | [ ] There must be no blank line following an inline comment
65 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
67 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
68 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
69 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
70 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
71 | ERROR | [x] Object operator not indented correctly; expected 18 spaces but found 33
74 | ERROR | [x] Array indentation error, expected 39 spaces but found 41
75 | ERROR | [x] Array indentation error, expected 39 spaces but found 41
76 | ERROR | [x] Array indentation error, expected 39 spaces but found 41
77 | ERROR | [x] Array indentation error, expected 39 spaces but found 41
80 | ERROR | [x] Object operator not indented correctly; expected 33 spaces but found 20
81 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
81 | ERROR | [x] Expected newline after closing brace
82 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
86 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 16
86 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
87 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
89 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
89 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
90 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
92 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
96 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
96 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
97 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
99 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
99 | ERROR | [ ] Missing short description in doc comment
100 | ERROR | [ ] Missing parameter comment
102 | ERROR | [ ] Description for the @return value is missing
104 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
105 | ERROR | [x] Opening brace should be on the same line as the declaration
106 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
106 | WARNING | [ ] Line exceeds 80 characters; contains 86 characters
106 | ERROR | [x] Comments may not appear after statements
107 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
107 | WARNING | [ ] Line exceeds 80 characters; contains 86 characters
107 | ERROR | [x] Comments may not appear after statements
108 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
109 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
109 | WARNING | [ ] Line exceeds 80 characters; contains 87 characters
109 | ERROR | [x] Comments may not appear after statements
110 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
110 | ERROR | [x] Expected 1 blank line after function; 2 found
113 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
113 | ERROR | [ ] Missing short description in doc comment
114 | ERROR | [ ] Description for the @return value is missing
116 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
117 | ERROR | [x] Opening brace should be on the same line as the declaration
118 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
122 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
124 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
124 | ERROR | [ ] Missing short description in doc comment
125 | ERROR | [ ] Missing parameter comment
127 | ERROR | [ ] Description for the @return value is missing
129 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
130 | ERROR | [x] Opening brace should be on the same line as the declaration
131 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
132 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
133 | ERROR | [x] Object operator not indented correctly; expected 14 spaces but found 29
135 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
135 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
136 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
136 | ERROR | [x] Expected newline after closing brace
137 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
141 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 12
141 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
142 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
143 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
145 | ERROR | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 86 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/ct_expire/src/Plugin/Field/FieldWidget/DateAndTimeCacheExpireWidget.php
------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 5 WARNINGS AFFECTING 6 LINES
------------------------------------------------------------------------------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
6 | WARNING | [x] Unused use statement
7 | WARNING | [x] Unused use statement
8 | WARNING | [x] Unused use statement
9 | WARNING | [x] Unused use statement
24 | ERROR | [x] Opening brace should be on the same line as the declaration
------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Use the below command with arguments.
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml web/modules/custom/ct_expire

Proposed resolution

Fix the phpcs issue

📌 Task
Status

Fixed

Component

Code

Created by

🇮🇳India Ashutosh Ahirwal India

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 @Ashutosh Ahirwal
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Ashutosh Ahirwal India

    Providing patch with fixes.

  • Assigned to arti_parmar
  • Issue was unassigned.
  • 🇮🇳India arti_parmar

    Kindly review patch.

  • 🇮🇳India Anmol_Specbee

    The patch mentioned in comment#4 resolves all the errors. Moving it to RTBC.

  • Status changed to RTBC over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -`$ct_expire->schedule('node:12', time(), 'node_12_paragraph_21_field_publish_date');`
    +`$ct_expire->schedule('node:12',
    +time(),'node_12_paragraph_21_field_publish_date');`

    Code lines are not required to be shorter than 81 characters. Line length and wrapping , part of the Drupal coding standards, says:

    • Lines containing longer function names, function/class definitions, variable declarations, etc are allowed to exceed 80 characters.
    • Control structure conditions may exceed 80 characters, if they are simple to read and understand.

    (Emphasis is mine.)

    The existing code is simpler to understand, contrarily to the changed code, which is also wrongly formatted.

    -* CT expire comes with a form widget that allows you to automatically create invalidation items.
    +* CT expire comes with a form widget that allows you to automatically
    +create invalidation items.

    Since that text is part of a list, the second line must be indented.

    +  /**
    +   * A logger instance.
    +   *

    The used article is not correct: The definite article is used in all the parameter/property descriptions.

    +  /**
    +   * The object constructor.
    +   *
    +   * @param \Drupal\Core\Database\Connection $connection
    +   *   The database connection.
    +   * @param \Drupal\Component\Datetime\TimeInterface $time
    +   *   The time service.
    +   * @param \Psr\Log\LoggerInterface $logger
    +   *   A logger instance.
    +   */
    +  public function __construct(Connection $connection, TimeInterface $time, LoggerInterface $logger) {
    

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

    +        $this->connection->merge('ct_expire_item')
    +          ->key(['name' => $name])
    +          ->fields(
    +                               [
    +                                 'name' => $name,
    +                                 'cache_tag' => $tag,
    +                                 'expire' => $timestamp,
    +                                 'created' => $this->time->getCurrentTime(),
    +                               ]
    +                           )
    +          ->execute();

    The indentation used from Drupal code is two spaces. That means the indentation cannot pass from 10 spaces in a line to 16 spaces in the next line; it can only be increased of two spaces at time.

    +      catch (\Exception $e) {
             $this->logger->error(
    -            'Unexpected error creating cache expire tag with name: %name',
    -            ['%name' => $name]
    -        );
    -        return false;
    -    }
    +              'Error creating cache expire tag %name : %error.',
    +              ['%name' => $name, '%error' => $e->getMessage()]
    +          );

    The existing code is not equivalent to the changed code.

    +  /**
    +   * {@inheritdoc}
    +   */
    +  private function cleanString(string $string) {
    

    Since that method is private, it is probably not defined in a parent class. Therefore, {@inheritdoc} cannot be used for its documentation comment.

  • Assigned to nitin_lama
  • First commit to issue fork.
  • @bharath-kondeti opened merge request.
  • Status changed to Needs review over 1 year ago
  • Issue was unassigned.
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Fixed over 1 year ago
  • 🇳🇱Netherlands willempje2

    So i resolved some of the issues mentioned in comments from apaderno in separate branch fetched from the PR from bharath-kondeti.
    These changes are now merged and available in new tag.

    If someone is willing to do another code snif that would be much appreciated.
    For now i will set the status to fixed and try to credit everyone involved.

    As you may notice i am a bit new to this, so if i forgot anything (in crediting or in the workflow) please let me know.

  • Status changed to Fixed over 1 year ago
Production build 0.71.5 2024