Skip to content

Instantly share code, notes, and snippets.

@gsherwood
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsherwood/8969567 to your computer and use it in GitHub Desktop.
Save gsherwood/8969567 to your computer and use it in GitHub Desktop.
Example output from PHP_CodeSniffer's Information report (--report=info)
Running with a single standard will allow sniffs in that standard to add metrics about the source code.
This is a good way to get a feel for how a code base is deviating from a standard and ways you can
tweak the standard to more closely match what the majority of developers are doing.
The report output is still very rough, so read output like this:
Function openning brace placement: new line [10431/10598, 98.42%]
same line => 167 (1.58%)
as this:
The majority of function openning braces are placed on a new line (98.42%).
PHPCS checked 10598 function openning braces and found 10431 of them were like this.
PHPCS also found that some braces were on the same line; 167 of them, which is 1.58%.
And output like this:
PHP keyword case: lower [87067/87081, 99.98%]
upper => 10 (0.01%)
mixed => 4 (0%)
as this:
The majorty of PHP keywords are defined in lower case (99.98%).
PHPCS checked 87081 keywords and found 87067 of them were defined in lower case.
PHPCS also found that 10 keywords were defined in upper case (0.01%) and 4 were mixed case (< 0.01%).
Run over ZF2's library directory with PSR2 standard
(phpcs zf2/library/ --report=info --standard=PSR2)
PHP CODE SNIFFER INFORMATION REPORT
--------------------------------------------------------------------------------
-----------
| Classes |
-----------
One class per file: yes [2003/2003, 100%]
Class defined in namespace: yes [2003/2003, 100%]
CamelCase class name: yes [2002/2003, 99.95%]
no => 1 (0.05%)
---------------------
| ControlStructures |
---------------------
Spaces after control structure open parenthesis: 0 [14374/14380, 99.96%]
3 => 4 (0.03%)
1 => 2 (0.01%)
Spaces before control structure close parenthesis: 0 [14033/14036, 99.98%]
1 => 3 (0.02%)
Control structure defined inline: no [14662/14695, 99.78%]
yes => 33 (0.22%)
Use of ELSE IF or ELSEIF: elseif [808/808, 100%]
---------
| Files |
---------
Blank lines at EOF: 1 [2261/2261, 100%]
Number of newlines at EOF: 1 [2261/2261, 100%]
Declarations and side effects mixed: no [2244/2261, 99.25%]
yes => 17 (0.75%)
EOL char: \n [2261/2261, 100%]
PHP closing tag at EOF: no [2261/2261, 100%]
Line length: < 80 [263422/282530, 93.24%]
81-120 => 18438 (6.53%)
121-150 => 483 (0.17%)
> 150 => 187 (0.07%)
-------------
| Functions |
-------------
Function openning brace placement: new line [10432/10599, 98.42%]
same line => 167 (1.58%)
-----------
| Methods |
-----------
CamelCase method name: yes [11485/11492, 99.94%]
no => 7 (0.06%)
---------------------
| NamingConventions |
---------------------
Constant name case: upper [1194/1194, 100%]
-------
| PHP |
-------
PHP short open tag used: no [2261/2261, 100%]
PHP keyword case: lower [87054/87068, 99.98%]
upper => 10 (0.01%)
mixed => 4 (0%)
PHP constant case: lower [9397/9402, 99.95%]
upper => 5 (0.05%)
--------------
| WhiteSpace |
--------------
Line indent: spaces [150769/150769, 100%]
--------------------------------------------------------------------------------
Time: 46.71 seconds, Memory: 34.50Mb
You can also run multiple standards over the code base to give a better sense of the way code is
written. This can be used to help forumulate a completley custom standard, or to make a custom
standard more strict by bringing in more checks.
Run over ZF2's library directory with all standards
(phpcs zf2/library/ --report=info --standard=Generic,Squiz,Zend,PEAR,PSR2)
PHP CODE SNIFFER INFORMATION REPORT
--------------------------------------------------------------------------------
----------
| Arrays |
----------
Array keyword case: lower [5198/5198, 100%]
-----------
| Classes |
-----------
CamelCase class name: yes [2002/2003, 99.95%]
no => 1 (0.05%)
One class per file: yes [2003/2003, 100%]
Class defined in namespace: yes [2003/2003, 100%]
---------------------
| ControlStructures |
---------------------
Control structure defined inline: no [14662/14695, 99.78%]
yes => 33 (0.22%)
Use of ELSE IF or ELSEIF: elseif [808/808, 100%]
---------
| Files |
---------
Newline at EOF: yes [2261/2261, 100%]
EOL char: \n [2261/2261, 100%]
Line length: < 80 [263422/282530, 93.24%]
81-120 => 18438 (6.53%)
121-150 => 483 (0.17%)
> 150 => 187 (0.07%)
Lowercase filename: no [2259/2261, 99.91%]
yes => 2 (0.09%)
Blank lines at EOF: 1 [2261/2261, 100%]
Number of newlines at EOF: 1 [2261/2261, 100%]
PHP closing tag at EOF: no [2261/2261, 100%]
Declarations and side effects mixed: no [2244/2261, 99.25%]
yes => 17 (0.75%)
--------------
| Formatting |
--------------
Spacing after cast statement: 1 [974/977, 99.69%]
0 => 3 (0.31%)
-------------
| Functions |
-------------
Function openning brace placement: new line [10456/10667, 98.02%]
same line => 211 (1.98%)
-----------
| Methods |
-----------
CamelCase method name: yes [6262/6483, 96.59%]
no => 221 (3.41%)
---------------------
| NamingConventions |
---------------------
CamelCase method name: yes [5223/5355, 97.54%]
no => 132 (2.46%)
Constant name case: upper [1194/1194, 100%]
-------
| PHP |
-------
PHP short open tag used: no [2261/2261, 100%]
PHP keyword case: lower [87054/87068, 99.98%]
upper => 10 (0.01%)
mixed => 4 (0%)
PHP constant case: lower [9397/9402, 99.95%]
upper => 5 (0.05%)
-----------
| Strings |
-----------
Spacing before string concat: 1 [9273/10007, 92.67%]
newline => 681 (6.81%)
0 => 44 (0.44%)
2 => 4 (0.04%)
3 => 2 (0.02%)
4 => 2 (0.02%)
6 => 1 (0.01%)
Spacing after string concat: newline [5883/10007, 58.79%]
1 => 4057 (40.54%)
0 => 49 (0.49%)
2 => 18 (0.18%)
Brackets around echoed strings: no [64/64, 100%]
--------------
| WhiteSpace |
--------------
Line indent: spaces [150769/150769, 100%]
Spacing before object operator: 0 [32078/32186, 99.66%]
newline => 108 (0.34%)
Spacing after object operator: 0 [32186/32186, 100%]
Space after operator: 1 [42275/42479, 99.52%]
0 => 142 (0.33%)
2 => 43 (0.1%)
newline => 19 (0.04%)
Spaces after control structure open parenthesis: 0 [14374/14399, 99.83%]
1 => 21 (0.15%)
3 => 4 (0.03%)
Spaces before control structure close parenthesis: 0 [14377/14380, 99.98%]
1 => 3 (0.02%)
Space before operator: 1 [8741/9124, 95.8%]
0 => 165 (1.81%)
newline => 149 (1.63%)
5 => 24 (0.26%)
2 => 13 (0.14%)
4 => 11 (0.12%)
3 => 9 (0.1%)
6 => 4 (0.04%)
8 => 3 (0.03%)
10 => 2 (0.02%)
7 => 2 (0.02%)
9 => 1 (0.01%)
--------------------------------------------------------------------------------
Time: 1.75 minutes, Memory: 36.25Mb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment