Your SlideShare is downloading. ×
Php|tek '12  It's More Than Just Style
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Php|tek '12 It's More Than Just Style

6,157
views

Published on

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 …

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.

Published in: Technology

0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,157
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
19
Comments
0
Likes
10
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. It’s More Than Just Stylephp|Tek ’12May 23, 2012
    • 2. LB Denker@elblinkin an Etsy Admin
    • 3. First Things That Come To Mind
    • 4. What Difference Does Whitespace Make?
    • 5. With Modern Monitors,Line Length Does Not Matter.
    • 6. It’s Just Style!
    • 7. The Argument for Style
    • 8. Requires Less Human Cognitive Effort to Work with Code
    • 9. Sniffs That Save You
    • 10. DuplicateClass NameYou can not have two classes or interfaceswith the same name
    • 11. DuplicateFunctionArgumentYou can not have two arguments in afunction with the same name
    • 12. Static $thisUsage$this requires an instance
    • 13. Non-ExecutableCodeCode after a return or exit will not beexecuted
    • 14. ValidDefault ValueAll required arguments should precedeall optional arguments
    • 15. Closing TagAvoid sending headers early
    • 16. Minimal ruleset.xmlRun The Sniffs That Save You
    • 17. PHPCSruleset.xmlGeneratorhttp://edorian.github.com/php-coding-standard-generator/#phpcs
    • 18. LeadingWhitespaceCustom Sniff to Avoid sending headersearly
    • 19. Full ReportRunning phpcs
    • 20. Summary ReportRunning phpcs
    • 21. Source ReportRunning phpcs
    • 22. XML ReportRunning phpcs
    • 23. CSV ReportRunning phpcs
    • 24. Emacs ReportRunning phpcs
    • 25. Blame Report(git|svn)Running phpcs
    • 26. Blame Report(git|svn)Running phpcs
    • 27. Checkstyle ReportRunning phpcs
    • 28. Checkstyle Plugin — JenkinsRunning phpcs in Jenkins
    • 29. Checkstyle Plugin — JenkinsRunning phpcs in Jenkins
    • 30. Checkstyle Plugin — JenkinsRunning phpcs in Jenkins
    • 31. PHP Templatefor Jenkinshttp://jenkins-php.org/
    • 32. Step Back for a Minute
    • 33. Don’t Forget Lint php -l
    • 34. Steps To Clean Code✤ Start with Syntax✤ Move to Style✤ Then Design... maybe
    • 35. Standards to Drive Conventions
    • 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
    • 37. Standards to Move You Forward
    • 38. Sniff OutBackwardsIncompatibilityCoding Standards to Help You Upgrade
    • 39. Upgrade to PHP 5.3✤ Deprecated Functions✤ Deprecated ini Directives✤ Deprecated new Reference Return✤ Forbidden Names, Reserved Keywords✤ Non-Static Magic Methods, Ensure✤ Removed Extensions https://github.com/wimg/PHP53Compat_CodeSniffer
    • 40. Compatibility Through PHP 5.4✤ Default Timezone Required✤ Deprecated Functions✤ Deprecated ini Directives✤ Deprecated new Reference Return✤ Forbidden continue and break Variable Arguments✤ Forbidden Names, Reserved Keywords✤ Non-Static Magic Methods, Ensure✤ Removed Extensions✤ Removed Hash Algorithms https://github.com/wimg/PHPCompatibility
    • 41. Standards to Save You Time
    • 42. PHPUnit Coding Standard✤ Ensures Tests are Executable✤ Reduces Superfluous Code✤ Increases Readability✤ Decreases Debug Time
    • 43. Minimal phpunit-ruleset.xmlRun The Sniffs That Save You
    • 44. Code Sniffer Limitations
    • 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
    • 46. CSRunnerOnly analyze recent changeshttps://github.com/elblinkin/CSRunner
    • 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
    • 48. Beyond Code Sniffer
    • 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
    • 54. PHPMess Detectorhttp://phpmd.org/
    • 55. ✤ http://phpadvent.org/2011/more-than-just-style-by- laura-beth-denker✤ http://codeascraft.com✤ http://www.slideshare.net/Etsy✤ http://elblinkin.info✤ http://www.lornajane.net/posts/2009/php-code- sniffer-tutorial-on-techportal