Skip to content

Instantly share code, notes, and snippets.

@void285
Created May 5, 2020 05:44
Show Gist options
  • Save void285/ba21aa84e49752fe37924667e43948f5 to your computer and use it in GitHub Desktop.
Save void285/ba21aa84e49752fe37924667e43948f5 to your computer and use it in GitHub Desktop.
PHP CodeSniffer sniffer result statistic script.

The cmd do following actions:

  • get phpcs result
  • normalize string
  • normalize zero and non-zero numbers
  • normalize functions
  • normalize vars
  • uniq and sort
  • output

phpcs --standard=squiz demo.php | awk -F"|" '{print $2 $3}' | sed 's/"[^"]\+"/"some_str"/g' | sed 's/ 0 / ze-ro /g' | sed 's/[0-9]\+/5/g'| sed 's/ze-ro/0/g' | sed 's/[a-zA-Z0-9_]\+()/some_function()/g' | sed 's/\$[a-zA-Z0-9_]\+/$some_var/g' | sort | uniq -c | sort -nr

result example

    910  ERROR    [ ] Variable "some_str" is not in valid camel caps format
    318  ERROR    [x] Equals sign not aligned with surrounding assignments; expected 5 spaces but found 5 space
    222  ERROR    [x] No blank line found after control structure
    212  ERROR    [x] Array double arrow not aligned correctly; expected 5 space(s) but found 5
    174  ERROR    [x] Expected 5 blank line before closing function brace; 0 found
    174  ERROR    [x] Expected //end some_function()
    169  ERROR    [x] Expected 5 blank lines after function; 5 found
    163  ERROR    [ ] Inline comments must end in full-stops, exclamation marks, or question marks
    152  WARNING  [ ] Consider putting global function "some_str" in a static class
    149  ERROR    [x] Array with multiple values cannot be declared on a single line
    149  ERROR    [ ] Missing doc comment for function some_function()
    117  ERROR    [ ] Inline comments must start with a capital letter
    109  WARNING  [ ] Line exceeds 5 characters; contains 5 characters
    108  ERROR    [ ] Implicit true comparisons prohibited; use === TRUE instead
    107  ERROR    [x] Concat operator must not be surrounded by spaces
     93  ERROR    [ ] Inline IF statements are not allowed
     77  ERROR    [x] Short array syntax must be used to define arrays
     69  ERROR    [x] Incorrect spacing between default value and equals sign for argument "some_str"; expected 0 but found 5
     69  ERROR    [x] Incorrect spacing between argument "some_str" and equals sign; expected 0 but found 5
     59  ERROR    [x] Expected 5 space before "some_str"; 0 found
     58  ERROR    [x] Expected 5 space after "some_str"; 0 found
     53  ERROR    [ ] Operator ! prohibited; use === FALSE instead
     51  ERROR    [ ] The value of a comparison must not be assigned to a variable
     50  ERROR    [x] Operation must be bracketed
     36  ERROR    [ ] Inline shorthand IF statement requires brackets around comparison
     31  ERROR    [ ] Operator == prohibited; use === instead
     26  ERROR    [ ] Use of the "some_str" keyword is forbidden; use "some_str" instead
     25  ERROR    [ ] Doc comment for parameter "some_str" missing
     22  WARNING  [ ] This comment is 5% valid code; is this commented out code?
     22  ERROR    [x] Expected 5 blank lines before function; 5 found
     22  ERROR    [ ] Missing @return tag in function comment
     21  ERROR    [x] Only one argument is allowed per line in a multi-line function call
     21  ERROR    [ ] There must be no blank lines after the function comment
     19  ERROR    [x] String "some_str" does not require double quotes; use single quotes instead
     19  ERROR    [x] Array key not indented correctly; expected 5 spaces but found 5
     16  ERROR    [x] Opening parenthesis of a multi-line function call must be the last content on the line
     16  ERROR    [x] Closing parenthesis of a multi-line function call must be on a line by itself
     15  ERROR    [x] Each value in a multi-line array must be on a new line
     14  ERROR    [x] Each line in an array declaration must end in a comma
     13  ERROR    [x] End comment for long condition not found; expected "some_str"
     11  ERROR    [ ] Function name "some_str" is not in camel caps format
     11
      9  ERROR    [x] Comments may not appear after statements
      8  ERROR    [x] Case breaking statement must be indented 5 spaces from SWITCH keyword
      6  ERROR    [x] Multi-line function call not indented correctly; expected 5 spaces but found 5
      6  ERROR    [x] Line indented incorrectly; expected at least 5 spaces, found 5
      6  ERROR    [x] Expected 5 space before comment text but found 5; use block comment if you need indentation
      6  ERROR    [x] Case breaking statements must be followed by a single blank line
      6  ERROR    [ ] Doc comment short description must start with a capital letter
      5  ERROR    [x] The first index in a multi-value array must be on a new line
      5  ERROR    [x] Comma required after last value in array declaration
      4  ERROR    [x] Equals sign not aligned correctly; expected 5 space but found 0 spaces
      4  ERROR    [ ] Variable "some_str" not allowed in double quoted string; use concatenation instead
      4  ERROR    [ ] Type hint "some_str" missing for $some_var
      4  ERROR    [ ] Parameter comment must end with a full stop
      3  ERROR    [x] Each line in a multi-line IF statement must begin with a boolean operator
      3  ERROR    [x] Closing brace of array declaration must be on a new line
      3  ERROR    [ ] Parameter comment must start with a capital letter
      3  ERROR    [ ] Assignments must be the first block of code on a line
      2  ERROR    [x] There must be exactly one blank line before the tags in a doc comment
      2  ERROR    [x] Tag value for @param tag indented incorrectly; expected 5 spaces but found 5
      2  ERROR    [x] String "
      2  ERROR    [x] Inline shorthand IF statement requires 5 space before ELSE; 0 found
      2  ERROR    [x] Expected 5 blank lines after function; 0 found
      2  ERROR    [x] Array close brace not indented correctly; expected 5 spaces but found 5
      2  ERROR    [ ] Tag @return cannot be grouped with parameter tags in a doc comment
      2  ERROR    [ ] Comment required for empty DEFAULT case
      1  WARNING  [ ] Empty return statement not required here
      1  ERROR    [x] There must be no blank line following an inline comment
      1  ERROR    [x] Perl-style comments are not allowed; use "some_str" instead
      1  ERROR    [x] Last line of comment aligned incorrectly; expected 5 spaces but found 5
      1  ERROR    [x] Language constructs must be followed by a single space; expected 5 space but found "some_str"
      1  ERROR    [x] First line of comment not aligned correctly; expected 5 spaces but found 5
      1  ERROR    [x] File is being conditionally included; use "some_str" instead
      1  ERROR    [x] Expected 5 spaces after parameter type; 5 found
      1  ERROR    [x] Expected 5 spaces after parameter name; 5 found
      1  ERROR    [x] Expected 5 space after logical operator; 5 found
      1  ERROR    [x] Expected 5 blank lines before function; 0 found
      1  ERROR    [x] Expected //end class
      1  ERROR    [x] Equals sign not aligned with surrounding assignments; expected 5 spaces but found 5 spaces
      1  ERROR    [x] Closing parenthesis of a multi-line IF statement must be on a new line
      1  ERROR    [x] Block comments must be started with /*
      1  ERROR    [ ] You must use "some_str" style comments for a function comment
      1  ERROR    [ ] The use of some_function() inside a loop condition is not allowed; assign the return value to a variable and use the variable in the loop condition instead
      1  ERROR    [ ] Operator != prohibited; use !== instead
      1  ERROR    [ ] New objects must be assigned to a variable
      1  ERROR    [ ] Missing file doc comment
      1  ERROR    [ ] Inline shorthand IF statement must be declared on a single line
      1  ERROR    [ ] Inline doc block comments are not allowed; use "some_str" or "some_str" instead
      1  ERROR    [ ] Increment operators should be used where possible; found "some_str" but expected "some_str"
      1  ERROR    [ ] Empty line required before block comment
      1  ERROR    [ ] Empty line required after block comment
      1  ERROR    [ ] Empty IF statement detected
      1  ERROR    [ ] Decrement operators should be used where possible; found "some_str" but expected "some_str"
      1  ERROR    [ ] Class name doesn't match filename; expected "some_str"
      1  ERROR    [ ] Class found in "some_str" file; use "some_str" extension instead
      1  ERROR    [ ] Boolean operators are not allowed outside of control structure conditions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment