Fix the warnings/errors reported by PHP_CodeSniffer

Created on 1 July 2023, over 1 year ago
Updated 12 August 2023, over 1 year ago

Running shows these warnings/errors, which should be fixed.

FILE: ./otp_service/otp_service.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: ./otp_service/otp_service.info.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: ./otp_service/src/Service/OTPValidateService.php
-------------------------------------------------------------------------
FOUND 21 ERRORS AND 2 WARNINGS AFFECTING 17 LINES
-------------------------------------------------------------------------
  7 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\user\Entity\User.
 10 | ERROR   | [x] Doc comment short description must end with a full stop
 11 | ERROR   | [x] There must be exactly one blank line before the tags in a doc comment
 12 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 15 | ERROR   | [ ] Missing member variable doc comment
 20 | ERROR   | [x] There must be exactly one blank line before the tags in a doc comment
 20 | ERROR   | [ ] Missing parameter comment
 20 | ERROR   | [x] Data types in @param tags need to be fully namespaced
 22 | ERROR   | [x] Expected 1 blank line before function; 2 found
 22 | ERROR   | [x] There should be no white space before a closing ")"
 22 | ERROR   | [x] Expected 0 spaces before closing parenthesis; 1 found
 24 | ERROR   | [x] Expected 1 blank line after function; 2 found
 28 | ERROR   | [x] Doc comment short description must end with a full stop
 30 | ERROR   | [ ] Public method name "OTPValidateService::validateOTP" is not in lowerCamel format
 31 | WARNING | [ ] User::load calls should be avoided in classes, use dependency injection instead
 32 | ERROR   | [x] No space found before comment text; expected "// Get secret" but found "//Get secret"
 32 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 36 | ERROR   | [x] No space found before comment text; expected "// Validate code" but found "//Validate code"
 36 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 38 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 8
 39 | ERROR   | [x] Expected newline after closing brace
 40 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 8
 44 | ERROR   | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 18 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: ./otp_service/src/Form/QrCodeForm.php
-------------------------------------------------------------------------
FOUND 57 ERRORS AND 10 WARNINGS AFFECTING 42 LINES
-------------------------------------------------------------------------
   1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
   2 | ERROR   | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
  11 | WARNING | [x] Unused use statement
  11 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\user\Entity\User.
  11 | ERROR   | [x] There must be one blank line after the last USE statement; 2 found;
  14 | ERROR   | [x] Missing class doc comment
  28 | ERROR   | [x] No space found before comment text; expected "// check if there's already a secret defined for this user" but
     |         |     found "//check if there's already a secret defined for this user"
  28 | ERROR   | [x] Inline comments must start with a capital letter
  28 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  29 | ERROR   | [x] Namespaced classes/interfaces/traits should be referenced with use statements
  29 | WARNING | [ ] User::load calls should be avoided in classes, use dependency injection instead
  29 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
  31 | ERROR   | [x] No space found before comment text; expected "// if there is no secret we allow the user to generate it" but
     |         |     found "//if there is no secret we allow the user to generate it"
  31 | ERROR   | [x] Inline comments must start with a capital letter
  31 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  32 | ERROR   | [x] Expected 1 space after IF keyword; 0 found
  32 | ERROR   | [x] Expected 1 space after closing parenthesis; found 0
  41 | ERROR   | [x] Whitespace found at end of line
  46 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
  48 | ERROR   | [x] Whitespace found at end of line
  49 | ERROR   | [x] Whitespace found at end of line
  53 | ERROR   | [x] Whitespace found at end of line
  54 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 4
  55 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 4
  55 | ERROR   | [x] No space found before comment text; expected "// if there's already a secret we inform the user" but found
     |         |     "//if there's already a secret we inform the user"
  55 | ERROR   | [x] Inline comments must start with a capital letter
  55 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  56 | ERROR   | [x] Expected newline after closing brace
  56 | ERROR   | [x] Expected 1 space after ELSE keyword; 0 found
  58 | ERROR   | [x] Whitespace found at end of line
  61 | ERROR   | [x] Concat operator must be surrounded by a single space
  61 | ERROR   | [x] Expected 0 spaces between "''" and comma; 1 found
  71 | ERROR   | [x] Whitespace found at end of line
  76 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
  79 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 4
  81 | ERROR   | [x] Expected 1 blank line after function; 3 found
  84 | ERROR   | [ ] More than 2 empty lines are not allowed
  85 | ERROR   | [ ] Public method name "QrCodeForm::generateQRCode" is not in lowerCamel format
  85 | ERROR   | [x] Missing function doc comment
  86 | ERROR   | [x] No space found before comment text; expected "// Generate Secret Key" but found "//Generate Secret Key"
  86 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  89 | ERROR   | [x] No space found before comment text; expected "// Get username of logged in user and set secret value" but
     |         |     found "//Get username of logged in user and set secret value"
  89 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  90 | ERROR   | [x] Namespaced classes/interfaces/traits should be referenced with use statements
  90 | WARNING | [ ] User::load calls should be avoided in classes, use dependency injection instead
  90 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
  94 | ERROR   | [x] No space found before comment text; expected "// Get hostname" but found "//Get hostname"
  94 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  95 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
  96 | ERROR   | [x] No space found before comment text; expected "// Generate QR Code URL" but found "//Generate QR Code URL"
  96 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  98 | ERROR   | [x] No space found before comment text; expected "// Logic to generate markup" but found "//Logic to generate
     |         |     markup"
  98 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  99 | ERROR   | [x] Concat operator must be surrounded by a single space
 101 | ERROR   | [x] Whitespace found at end of line
 104 | ERROR   | [x] Missing function doc comment
 105 | ERROR   | [x] No space found before comment text; expected "// Clear secret from the user" but found "//Clear secret from
     |         |     the user"
 105 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 106 | ERROR   | [x] Namespaced classes/interfaces/traits should be referenced with use statements
 106 | WARNING | [ ] User::load calls should be avoided in classes, use dependency injection instead
 106 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 107 | ERROR   | [x] Expected one space after the comma, 0 found
 111 | ERROR   | [x] Whitespace found at end of line
 114 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
 115 | ERROR   | [x] Expected 5 space(s) before asterisk; 3 found
 116 | ERROR   | [x] Expected 5 space(s) before asterisk; 3 found
 121 | ERROR   | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 58 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: ./otp_service/src/Plugin/Block/QRCodeBlock.php
-------------------------------------------------------------------------
FOUND 4 ERRORS AND 3 WARNINGS AFFECTING 5 LINES
-------------------------------------------------------------------------
  6 | WARNING | [x] Unused use statement
  7 | WARNING | [x] Unused use statement
  7 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Form\FormBuilderInterface.
 25 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 6
 25 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 26 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 6
 29 | ERROR   | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: ./otp_service/otp_service.module
-------------------------------------------------------------------------
FOUND 38 ERRORS AFFECTING 35 LINES
-------------------------------------------------------------------------
  9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Field\BaseFieldDefinition.
 15 | ERROR | [x] Additional blank lines found at end of doc comment
 17 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 18 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
 19 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 8
 20 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 8
 21 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 8
 23 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 8
 26 | ERROR | [x] Whitespace found at end of line
 27 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 28 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
 28 | ERROR | [x] Closing brace indented incorrectly; expected 0 spaces, found 2
 28 | ERROR | [x] Expected 1 blank line after function; 2 found
 31 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
 32 | ERROR | [x] Expected 3 space(s) before asterisk; 1 found
 33 | ERROR | [x] Expected 3 space(s) before asterisk; 1 found
 35 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 36 | ERROR | [x] Whitespace found at end of line
 37 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 38 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 39 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
 44 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 45 | ERROR | [x] Whitespace found at end of line
 46 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 47 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
 47 | ERROR | [x] Closing brace indented incorrectly; expected 0 spaces, found 2
 49 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
 50 | ERROR | [x] Expected 3 space(s) before asterisk; 1 found
 51 | ERROR | [x] Expected 3 space(s) before asterisk; 1 found
 52 | ERROR | [ ] otp_service_install() is an installation hook and must be declared in an install file
 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] Whitespace found at end of line
 58 | ERROR | [x] Expected 1 space(s) before asterisk; 0 found
 59 | ERROR | [x] Expected 1 space(s) before asterisk; 0 found
 60 | ERROR | [ ] otp_service_uninstall() is an installation hook and must be declared in an install file
 61 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
 62 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 36 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: ./otp_service/README.md
-------------------------------------------------------------------------
FOUND 0 ERRORS AND 11 WARNINGS AFFECTING 11 LINES
-------------------------------------------------------------------------
 18 | WARNING | Line exceeds 80 characters; contains 117 characters
 19 | WARNING | Line exceeds 80 characters; contains 84 characters
 20 | WARNING | Line exceeds 80 characters; contains 91 characters
 26 | WARNING | Line exceeds 80 characters; contains 92 characters
 27 | WARNING | Line exceeds 80 characters; contains 81 characters
 29 | WARNING | Line exceeds 80 characters; contains 106 characters
 30 | WARNING | Line exceeds 80 characters; contains 107 characters
 31 | WARNING | Line exceeds 80 characters; contains 109 characters
 38 | WARNING | Line exceeds 80 characters; contains 88 characters
 53 | WARNING | Line exceeds 80 characters; contains 113 characters
 56 | WARNING | Line exceeds 80 characters; contains 107 characters
-------------------------------------------------------------------------

Time: 53ms; Memory: 10MB
📌 Task
Status

Fixed

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.

  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

  • Issue created by @sonam_sharma
  • Issue was unassigned.
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India Anjali Mehta

    Hello @sonam_sharma ,
    I have reviewed your patch & Implemented it on my website having version 9.5.9 And PHP version - 8.1
    I am adding some screenshots(before/after applying the patch) for your reference.
    Please have a look at these screenshots.

    Thank You.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The issue summary should always describe what the issue is trying to fix and, in the case of coding standards issues, show which command and arguments have been used and which report that command shown. In this way, project maintainers can verify the patch/MR fixes all the warnings/errors.

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

    Please review.

  • Assigned to nitin_lama
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India nitin_lama India

    Apologies, updated the wrong issue.

  • 🇮🇳India nitin_lama India

    Fixed most of the errors/warning. Updated patch,

    Errors/warning remaining:

    FILE: /home/system/Documents/contribution/otp_service-3371754/otp_service.module
    ------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    ------------------------------------------------------------------------------------------------------
     50 | ERROR | otp_service_install() is an installation hook and must be declared in an install file
     58 | ERROR | otp_service_uninstall() is an installation hook and must be declared in an install file
    ------------------------------------------------------------------------------------------------------
    
    FILE: /home/system/Documents/contribution/otp_service-3371754/src/Form/QrCodeForm.php
    ----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------
     135 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ----------------------------------------------------------------------------------------------
    
    
    FILE: /home/system/Documents/contribution/otp_service-3371754/src/Plugin/Block/QRCodeBlock.php
    ----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------
     23 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ----------------------------------------------------------------------------------------------
    
    Time: 33ms; Memory: 6MB
    
  • @nitin_lama opened merge request.
  • Issue was unassigned.
  • 🇮🇳India nitin_lama India

    Created MR for the change.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The issue summary still does not show which command and which arguments have been used to obtain the report.

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

    I have updated issue summary.

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

    Running PHP_CodeSniffer, I get more warnings/errors.

  • 🇵🇹Portugal nsalves

    Thanks for the feedback, all issues were fixed in the newest release

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024