Mention PHP CodeSniffer, and most will think it’s just for style. Add passing PHP CodeSniffer to your test suites, and hear the groans. Why are we wasting time on whitespace rules? Why does it matter that my lines are longer than X characters? The answer: PHP CodeSniffer is more than just style. In this talk we will discuss what sniffs can save you from runtime errors, sniffs that can help you upgrade your PHP install, and sniffs that can help you find the bits of code that are slowing down you and your team.
36. Etsy Custom Sniffs
✤ Goto ✤ Integration Test
✤ Disallow goto ✤ Ensure that All Tests in a
@group are Marked @medium
✤ SvnTag or Higher
✤ Disallow SVN Tags
ie. $Date$ or $Revision$ ✤ Test Group
✤ Ensure that All Tests are
✤ UnnecessaryComment Marked in a @group that
✤ Disallow phpDoc Tags that Exists
Repeat Info in Source Control
ie. @author
45. How Code Sniffer Basically Works
✤ Gets array of Tokens from token_get_all()
✤ Creates Abstract Syntax Tree (AST)
✤ Analyzes Each File Individually, Sequentially
✤ Collects All Parsed, Analyzed Files in an array for Multi-File Sniffs
47. HpHp as a Static Analyzer
✤ Pros ✤ Cons
✤ Very Fast Static Analysis ✤ Not Easy to Install
✤ Call Graph Analysis ✤ Takes a Decent Amount of
Configuration
✤ HpHp Analyzer Creates
Checkstyle Reports
49. Steps To Clean Code
✤ Start with Syntax
✤ Move to Style
✤ Then Design... maybe
50. Enforcing a Standard
✤ Draft a Coding Standard
✤ Experiment with Various Sniffs, Tweak Sniffs
✤ Discover Actual Coding Tendencies
✤ Decide on Changes to Coding Standard Based on Previous Steps
✤ Strategize on How to Get to GREEN
51. PHP Community Standard
✤ Checkout PSR-1
✤ Checkout PSR-2
✤ Just-in: PHP Coding Standards Fixer
✤ http://cs.sensiolabs.org/
52. Moving Towards Enforcement
✤ Assign Violations via blame
✤ Create a Staging Set that Can Be Ignored in an Emergency
✤ Fix-It Competition or Party
53. Steps To Clean Code
✤ Start with Syntax
✤ Move to Style
✤ Then Design... maybe