Skip to content

Instantly share code, notes, and snippets.

Code sniffing

Greg Sherwood gsherwood

Code sniffing
View GitHub Profile
gsherwood / 21-Feb-2014.json
Last active Aug 29, 2015
Comparison of coding standards across some well known PHP projects
View 21-Feb-2014.json
"Array keyword case":{
gsherwood / zf2.txt
Last active Aug 29, 2015
Example output from PHP_CodeSniffer's Information report (--report=info)
View zf2.txt
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%).
gsherwood / gist:8275236
Last active Feb 17, 2016
Possible fix for bug #20151 : Problem handling "if(): ... else: ... endif;" syntax
View gist:8275236
$ git diff
diff --git a/CodeSniffer/File.php b/CodeSniffer/File.php
index f45e307..e629fed 100644
--- a/CodeSniffer/File.php
+++ b/CodeSniffer/File.php
@@ -1446,7 +1446,7 @@ class PHP_CodeSniffer_File
$type = $tokens[$i]['type'];
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
- echo "\tStart scope map at $i: $type => $content".PHP_EOL;
gsherwood / gist:6773172
Last active Dec 24, 2015
PHP_CodeSniffer (phpcs-fixer branch) run over ZF2. Shows all existing errors (warnings are muted) and which ones can be fixed automatically using phpcbf (docs:
View gist:6773172
$ php scripts/phpcs ../zf2/library/Zend/ --standard=PSR2 -p --report=source -ns
[x] PSR2.Methods.FunctionCallSignature.Indent 328
[ ] PSR2.Methods.FunctionCallSignature.MultipleArguments 276
[x] PSR2.Methods.FunctionCallSignature.CloseBracketLine 248
[x] Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore 230