Fix the issues reported by PHPCS

Created on 20 April 2023, over 1 year ago
Updated 26 September 2023, about 1 year ago

Problem/Motivation

FILE: ...pal10/web/modules/contrib/accession_reference/accession_reference.install
-------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
-------------------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
4 | 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."
5 | ERROR | [ ] Doc comment short description must be on a single line,
| | further text should be a separate paragraph
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ...l/contribution/drupal10/web/modules/contrib/accession_reference/README.md
-------------------------------------------------------------------------------
FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
-------------------------------------------------------------------------------
3 | WARNING | Line exceeds 80 characters; contains 93 characters
6 | WARNING | Line exceeds 80 characters; contains 95 characters
7 | WARNING | Line exceeds 80 characters; contains 93 characters
8 | WARNING | Line exceeds 80 characters; contains 90 characters
9 | WARNING | Line exceeds 80 characters; contains 87 characters
-------------------------------------------------------------------------------

FILE: .../accession_reference/tests/src/Functional/AccessionReferenceFieldTest.php
-------------------------------------------------------------------------------
FOUND 5 ERRORS AND 3 WARNINGS AFFECTING 6 LINES
-------------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
6 | WARNING | [x] Unused use statement
8 | WARNING | [x] Unused use statement
44 | ERROR | [x] There must be exactly one blank line before the tags in a
| | doc comment
44 | ERROR | [x] Data types in @throws tags need to be fully namespaced
103 | ERROR | [x] Tag value indented incorrectly; expected 1 space but
| | found 7
106 | ERROR | [x] Separate the @dataProvider and @throws sections by a
| | blank line.
106 | ERROR | [x] Data types in @throws tags need to be fully namespaced
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ...reference/src/Plugin/Field/FieldFormatter/AccessionReferenceFormatter.php
-------------------------------------------------------------------------------
FOUND 18 ERRORS AFFECTING 9 LINES
-------------------------------------------------------------------------------
57 | ERROR | [x] Expected 1 space after ":"; 2 found
58 | ERROR | [x] Expected 1 space after ":"; 2 found
62 | ERROR | [x] Expected one space after the comma, 0 found
76 | ERROR | [x] No space found before comment text; expected "// $output =
| | $this->numberFormat($item->groupref, $item->itemref);" but
| | found "//$output = $this->numberFormat($item->groupref,
| | $item->itemref);"
82 | ERROR | [x] Expected 1 space(s) after cast statement; 0 found
83 | ERROR | [x] Expected 1 space(s) after cast statement; 0 found
108 | ERROR | [x] Expected 1 space(s) after cast statement; 0 found
109 | ERROR | [x] Expected 1 space(s) after cast statement; 0 found
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [ ] String concat is not required here; use a single string
| | instead
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [ ] String concat is not required here; use a single string
| | instead
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [x] Concat operator must be surrounded by a single space
113 | ERROR | [x] Concat operator must be surrounded by a single space
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 16 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ..._reference/src/Plugin/Field/FieldType/AccessionReferenceItemInterface.php
-------------------------------------------------------------------------------
FOUND 12 ERRORS AFFECTING 10 LINES
-------------------------------------------------------------------------------
9 | ERROR | [ ] Wrong function doc comment end; expected "*/", found "**/"
11 | ERROR | [x] Opening brace should be on the same line as the declaration
12 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
15 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
15 | ERROR | [x] Expected 1 blank line before function; 0 found
17 | 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
25 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
27 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
30 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
30 | ERROR | [x] Expected 1 blank line after function; 0 found
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 11 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ...accession_reference/src/Plugin/Field/FieldType/AccessionReferenceItem.php
-------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
-------------------------------------------------------------------------------
27 | ERROR | [x] Opening brace should be on the same line as the declaration
34 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
35 | ERROR | [x] Array closing indentation error, expected 4 spaces but
| | found 6
101 | ERROR | [x] There should be no white space before a closing "]"
191 | ERROR | [x] There must be exactly one blank line before the tags in a
| | doc comment
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ...ssion_reference/src/Plugin/Field/FieldWidget/AccessionReferenceWidget.php
-------------------------------------------------------------------------------
FOUND 14 ERRORS AND 8 WARNINGS AFFECTING 22 LINES
-------------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
9 | WARNING | [x] Unused use statement
31 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
32 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
33 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
34 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
35 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
36 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
37 | ERROR | [x] Array closing indentation error, expected 4 spaces but
| | found 6
92 | ERROR | [x] The first index in a multi-value array must be on a new
| | line
93 | ERROR | [x] Closing parenthesis of array declaration must be on a new
| | line
99 | ERROR | [x] The first index in a multi-value array must be on a new
| | line
100 | ERROR | [x] Closing parenthesis of array declaration must be on a new
| | line
120 | WARNING | [ ] Unused variable $groupref.
121 | WARNING | [ ] Unused variable $itemref.
126 | WARNING | [ ] Unused variable $digits_groupref.
128 | WARNING | [ ] Unused variable $digits_itemref.
144 | WARNING | [ ] Unused variable $digits_groupref.
151 | WARNING | [ ] Unused variable $digits_itemref.
158 | ERROR | [x] Expected 1 space after "=>"; 2 found
163 | ERROR | [ ] The array declaration extends to column 106 (the limit is
| | 80). The array content should be split up over multiple
| | lines
169 | ERROR | [ ] The array declaration extends to column 103 (the limit is
| | 80). The array content should be split up over multiple
| | lines
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 14 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ...ules/contrib/accession_reference/src/Element/AccessionReferenceWidget.php
-------------------------------------------------------------------------------
FOUND 31 ERRORS AND 6 WARNINGS AFFECTING 25 LINES
-------------------------------------------------------------------------------
9 | ERROR | [x] There must be one blank line after the last USE
| | statement; 2 found;
21 | ERROR | [x] Missing function doc comment
24 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces,
| | found 0
24 | ERROR | [x] 6 spaces found before inline comment; expected "//
| | '#pre_render' => [" but found "// '#pre_render' =>
| | ["
25 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces,
| | found 0
25 | ERROR | [ ] Comment indentation error, expected only 6 spaces
26 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces,
| | found 0
27 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces,
| | found 0
28 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces,
| | found 0
28 | ERROR | [ ] Comment indentation error, expected only 6 spaces
29 | WARNING | [x] There must be no blank line following an inline comment
29 | WARNING | [ ] There must be no blank line following an inline comment
29 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces,
| | found 0
40 | ERROR | [x] Line indented incorrectly; expected at least 6 spaces,
| | found 0
40 | ERROR | [x] 8 spaces found before inline comment; expected "//
| | [$class, 'groupElements']," but found "// [$class,
| | 'groupElements'],"
60 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
62 | ERROR | [ ] Type hint "array" missing for $element
63 | ERROR | [x] No space found before comment text; expected "// $element
| | = self::preRenderCompositeFormElement($element);" but
| | found "//$element =
| | self::preRenderCompositeFormElement($element);"
64 | ERROR | [x] Equals sign not aligned correctly; expected 1 space but
| | found 2 spaces
79 | WARNING | [x] A comma should follow the last multiline array item.
| | Found: ]
115 | ERROR | [x] Missing function doc comment
132 | WARNING | [ ] Line exceeds 80 characters; contains 109 characters
132 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 0
132 | ERROR | [x] 2 spaces found before inline comment; expected "// public
| | static function validateAccessionRef(&$element,
| | FormStateInterface $form_state, &$complete_form) {" but
| | found "// public static function
| | validateAccessionRef(&$element, FormStateInterface
| | $form_state, &$complete_form) {"
132 | ERROR | [x] Inline comments must start with a capital letter
133 | WARNING | [ ] There must be no blank line following an inline comment
133 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 0
133 | ERROR | [x] Inline comments must end in full-stops, exclamation
| | marks, question marks, colons, or closing parentheses
140 | ERROR | [x] Expected 1 space before opening brace; found 0
158 | ERROR | [ ] Missing short description in doc comment
159 | ERROR | [ ] Description for the @return value is missing
162 | ERROR | [x] Opening brace should be on the same line as the
| | declaration
164 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
164 | ERROR | [x] 4 spaces found before inline comment; expected "//
| | $callbacks[] = 'preRenderAccession';" but found "//
| | $callbacks[] = 'preRenderAccession';"
165 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
167 | ERROR | [x] Expected 1 blank line after function; 0 found
168 | ERROR | [x] The closing brace for the class must have an empty line
| | before it
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 28 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

FILE: ...upal10/web/modules/contrib/accession_reference/accession_reference.module
-------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 5 LINES
-------------------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
3 | ERROR | [x] When importing a class with "use", do not include a leading
| | \
16 | ERROR | [ ] Missing short description in doc comment
17 | ERROR | [ ] Missing parameter comment
18 | ERROR | [ ] If there is no return value for a function, there must not
| | be a @return tag.
18 | ERROR | [ ] Description for the @return value is missing
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------

Time: 812ms; Memory: 10MB

Steps to reproduce

Execute: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig accession_reference/

Proposed resolution

Fix all the issues reported for Drupal and DrupalPractice standards

Remaining tasks

Patch review and

FILE: ...ssion_reference/src/Plugin/Field/FieldWidget/AccessionReferenceWidget.php
-------------------------------------------------------------------------------
FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
-------------------------------------------------------------------------------
122 | WARNING | Unused variable $groupref.
123 | WARNING | Unused variable $itemref.
127 | WARNING | Unused variable $digits_groupref.
129 | WARNING | Unused variable $digits_itemref.
145 | WARNING | Unused variable $digits_groupref.
152 | WARNING | Unused variable $digits_itemref.
-------------------------------------------------------------------------------

Time: 970ms; Memory: 10MB

📌 Task
Status

RTBC

Version

1.0

Component

Code

Created by

🇮🇳India urvashi_vora Madhya Pradesh, 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 @urvashi_vora
  • Hi @urvashi_vora, thanks for the patch, I have review your patch.

    These are the steps I followed:

    1. Took clone from git version 1.0.x in drupal 10.1.x

    2. Ran this command:

    ./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig modules/contrib/accession_reference/

    3. Applied patch and again ran phpcs command,

    Found errors.

    4. I have created a patch and solve the remaining errors,

    then again check with phpcs command found no errors.

    Please Review.

  • Status changed to Needs work about 1 year ago
  • 🇵🇭Philippines clarkssquared

    Hi Satish_kumar,

    I applied your patch but I noticed that it's not properly applied, for your reference, below is the output of your patch in my terminal.

    ➜  accession_reference git:(1.0.x) curl https://www.drupal.org/files/issues/2023-09-14/coding-standard-fixed-3355324-2_0.patch | git apply -v
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 22825  100 22825    0     0  74960      0 --:--:-- --:--:-- --:--:-- 77372
    <stdin>:9: trailing whitespace.
    A Drupal project implementing a field type for Accession References, 
    <stdin>:10: trailing whitespace.
    a museum term describing 
    <stdin>:17: trailing whitespace.
    This particular field implements an accession reference with 
    <stdin>:19: trailing whitespace.
    numeric, with a separator character (default '/') 
    <stdin>:20: trailing whitespace.
    between them. While this could perhaps 
    Checking patch README.md...
    error: while searching for:
    # Accession Reference field type
    
    A Drupal project implementing a field type for Accession References, a museum term describing 
    the ID used to label a specific item in the museum's collection.
    
    This particular field implements an accession reference with two text fields, both of which are
    numeric, with a separator character (default '/') between them. While this could perhaps have
    been done using e.g. the double_field project, a new type enables additional functionality
    such as specifying min/max and, in general, a more complete understanding of the field.
    
    The project provides:
    
    
    error: patch failed: README.md:1
    error: README.md: patch does not apply
    Checking patch accession_reference.install...
    Checking patch accession_reference.module...
    Checking patch src/Element/AccessionReferenceWidget.php...
    Checking patch src/Plugin/Field/FieldFormatter/AccessionReferenceFormatter.php...
    error: while searching for:
      protected function numberFormat($number, $number2) {
        $field_settings = $this->getFieldSettings();
        $settings = $this->getSettings();
        $dgt_grp = strlen((string)($field_settings['groupref_max']) ?: 9999);
        $dgt_itm = strlen((string)($field_settings['itemref_max']) ?: 9999);
        $zp_grp = $settings['zeropad_groupref'] ? '0' : '';
        $zp_itm = $settings['zeropad_itemref'] ? '0' : '';
    
        $format = '%1$'.$zp_grp.$dgt_grp.'d'.'%3$s'.'%2$'.$zp_itm.$dgt_itm.'d';
    
        return sprintf($format, $number, $number2, $field_settings['separator']);
      }
    
    error: patch failed: src/Plugin/Field/FieldFormatter/AccessionReferenceFormatter.php:97
    error: src/Plugin/Field/FieldFormatter/AccessionReferenceFormatter.php: patch does not apply
    Checking patch src/Plugin/Field/FieldType/AccessionReferenceItem.php...
    Checking patch src/Plugin/Field/FieldType/AccessionReferenceItemInterface.php...
    Checking patch src/Plugin/Field/FieldWidget/AccessionReferenceWidget.php...
    Checking patch tests/src/Functional/AccessionReferenceFieldTest.php...
    Checking patch tests/src/Kernel/AccessionReferenceItemTest.php...

    Please check and fix the errors that are mentioned.

    Thank you

  • 🇮🇳India chetan 11

    Hi @clarkssquared
    I have fixed all the above issue for phpcs, please check the patch & screenshot.

  • Status changed to Needs review about 1 year ago
  • Hii

    Providing the updated patch all the remaining error were fixed.

    again check with phpcs coomand no error were found.

    Please Review.

  • 🇵🇭Philippines clarkssquared

    Hi Satish_kumar,

    I applied your patch #6 and I confirmed that it fixes all the PHPCS issues and erros. RTBC+1 for me

    Please look at the screenshot I attached for your reference.

    Thank you

  • Status changed to RTBC about 1 year ago
  • 🇮🇳India aayushDrupal

    Hi Satish_kumar,

    I have applied your patch #6 and found no phpcs errors. Screenshot attached for your reference .

    Moving to RTBC for now.

    Thanks

Production build 0.71.5 2024