SlideShare a Scribd company logo
1 of 55
It’s More Than Just Style
php|Tek ’12

May 23, 2012
LB Denker
@elblinkin an Etsy Admin
First Things That Come To Mind
What Difference Does
 Whitespace Make?
With Modern Monitors,
Line Length Does Not
       Matter.
It’s Just Style!
The Argument for Style
Requires Less Human Cognitive
   Effort to Work with Code
Sniffs That Save You
Duplicate
Class Name
You can not have two classes or interfaces
with the same name
Duplicate
Function
Argument
You can not have two arguments in a
function with the same name
Static $this
Usage
$this requires an instance
Non-Executable
Code
Code after a return or exit will not be
executed
Valid
Default Value
All required arguments should precede
all optional arguments
Closing Tag
Avoid sending headers early
Minimal ruleset.xml
Run The Sniffs That Save You
PHPCS
ruleset.xml
Generator
http://edorian.github.com/php-coding-
standard-generator/#phpcs
Leading
Whitespace
Custom Sniff to Avoid sending headers
early
Full Report
Running phpcs
Summary Report
Running phpcs
Source Report
Running phpcs
XML Report
Running phpcs
CSV Report
Running phpcs
Emacs Report
Running phpcs
Blame Report(git|svn)
Running phpcs
Blame Report(git|svn)
Running phpcs
Checkstyle Report
Running phpcs
Checkstyle Plugin — Jenkins
Running phpcs in Jenkins
Checkstyle Plugin — Jenkins
Running phpcs in Jenkins
Checkstyle Plugin — Jenkins
Running phpcs in Jenkins
PHP Template
for Jenkins
http://jenkins-php.org/
Step Back for a Minute
Don’t Forget Lint
    php -l
Steps To Clean Code



✤   Start with Syntax
✤   Move to Style
✤   Then Design... maybe
Standards to Drive Conventions
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
Standards to Move You Forward
Sniff Out
Backwards
Incompatibility
Coding Standards to Help You Upgrade
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
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
Standards to Save You Time
PHPUnit Coding Standard


✤   Ensures Tests are Executable

✤   Reduces Superfluous Code

✤   Increases Readability

✤   Decreases Debug Time
Minimal phpunit-ruleset.xml
Run The Sniffs That Save You
Code Sniffer Limitations
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
CSRunner
Only analyze recent changes
https://github.com/elblinkin/CSRunner
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
Beyond Code Sniffer
Steps To Clean Code



✤   Start with Syntax
✤   Move to Style
✤   Then Design... maybe
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
PHP Community Standard


✤   Checkout PSR-1

✤   Checkout PSR-2

✤   Just-in: PHP Coding Standards Fixer

    ✤   http://cs.sensiolabs.org/
Moving Towards Enforcement



✤   Assign Violations via blame

✤   Create a Staging Set that Can Be Ignored in an Emergency

✤   Fix-It Competition or Party
Steps To Clean Code



✤   Start with Syntax
✤   Move to Style
✤   Then Design... maybe
PHP
Mess Detector
http://phpmd.org/
✤   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

More Related Content

What's hot

What's hot (20)

2021 ZAP Automation in CI/CD
2021 ZAP Automation in CI/CD2021 ZAP Automation in CI/CD
2021 ZAP Automation in CI/CD
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
 
Testing Toolbox
Testing ToolboxTesting Toolbox
Testing Toolbox
 
Tdd using Jasmine and karma
Tdd using  Jasmine and karmaTdd using  Jasmine and karma
Tdd using Jasmine and karma
 
Five Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal SiteFive Easy Ways to QA Your Drupal Site
Five Easy Ways to QA Your Drupal Site
 
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
 
Debugging rails
Debugging railsDebugging rails
Debugging rails
 
2020 OWASP Thailand - ZAP intro
2020 OWASP Thailand - ZAP intro2020 OWASP Thailand - ZAP intro
2020 OWASP Thailand - ZAP intro
 
Tdd
TddTdd
Tdd
 
2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop
 
Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an HUnit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
 
Scripting robot
Scripting robotScripting robot
Scripting robot
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Javascript test frameworks
Javascript test frameworksJavascript test frameworks
Javascript test frameworks
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
Live Testing A Legacy App
Live Testing A Legacy AppLive Testing A Legacy App
Live Testing A Legacy App
 
How Testing Changed My Life
How Testing Changed My LifeHow Testing Changed My Life
How Testing Changed My Life
 
Appium & Robot Framework
Appium & Robot FrameworkAppium & Robot Framework
Appium & Robot Framework
 

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

Системный взгляд на параллельный запуск Selenium тестов
Системный взгляд на параллельный запуск Selenium тестовСистемный взгляд на параллельный запуск Selenium тестов
Системный взгляд на параллельный запуск Selenium тестов
COMAQA.BY
 

Similar to Php|tek '12 It's More Than Just Style (20)

Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.How do you tame a big ball of mud? One test at a time.
How do you tame a big ball of mud? One test at a time.
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Ui Testing with Ghost Inspector
Ui Testing with Ghost InspectorUi Testing with Ghost Inspector
Ui Testing with Ghost Inspector
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
Awesome Test Automation Made Simple w/ Dave Haeffner
Awesome Test Automation Made Simple w/ Dave HaeffnerAwesome Test Automation Made Simple w/ Dave Haeffner
Awesome Test Automation Made Simple w/ Dave Haeffner
 
PHPUnit Automated Unit Testing Framework
PHPUnit Automated Unit Testing FrameworkPHPUnit Automated Unit Testing Framework
PHPUnit Automated Unit Testing Framework
 
How does one learn to program?
How does one learn to program?How does one learn to program?
How does one learn to program?
 
Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium MeetupSelenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
Static analysis saved my code tonight
Static analysis saved my code tonightStatic analysis saved my code tonight
Static analysis saved my code tonight
 
Care and Feeding of Large Web Applications
Care and Feeding of Large Web ApplicationsCare and Feeding of Large Web Applications
Care and Feeding of Large Web Applications
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 
Системный взгляд на параллельный запуск Selenium тестов
Системный взгляд на параллельный запуск Selenium тестовСистемный взгляд на параллельный запуск Selenium тестов
Системный взгляд на параллельный запуск Selenium тестов
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 

More from LB Denker

Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons Learned
LB Denker
 
Php com con-2011
Php com con-2011Php com con-2011
Php com con-2011
LB Denker
 

More from LB Denker (8)

Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons Learned
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
phpDay 2012: Scaling Communication via Continuous Integration
phpDay 2012: Scaling Communication via Continuous IntegrationphpDay 2012: Scaling Communication via Continuous Integration
phpDay 2012: Scaling Communication via Continuous Integration
 
QC Merge 2012: Growing community
QC Merge 2012: Growing communityQC Merge 2012: Growing community
QC Merge 2012: Growing community
 
PHP UK Conference 2012: Scaling Communication via Continuous Integration
PHP UK Conference 2012: Scaling Communication via Continuous IntegrationPHP UK Conference 2012: Scaling Communication via Continuous Integration
PHP UK Conference 2012: Scaling Communication via Continuous Integration
 
Are Your Tests Really Helping You?
Are Your Tests Really Helping You?Are Your Tests Really Helping You?
Are Your Tests Really Helping You?
 
Php com con-2011
Php com con-2011Php com con-2011
Php com con-2011
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n