O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Containing Quality

Static analysis, unit testing, compatibility, and coding standards are all important metrics to monitor and perform regularly. However, the time to set up the various tools takes time and patience to set up and run...until now.

We'll see how using pre-configured Docker images make easy to have PHP code quality tools at our fingertips, ready to run or automate on a moments notice. Then will share tips to run the various tools, and/or create automation around running them regularly.

  • Entre para ver os comentários

  • Seja a primeira pessoa a gostar disto

Containing Quality

  1. 1. Containing Quality By: Adam Culp Twitter: @adamculp
  2. 2. 2 Containing Quality ● About me – OSS Contributor – PHP Certified – Zend Certification Advisory Board – PHP-Fig voting member (IBM i Toolkit) – Consultant at Zend Technologies – Organizer SoFloPHP (South Florida) – Organizer SunshinePHP (Miami) – Long distance (ultra) runner – Photography Enthusiast – Judo Black Belt Instructor
  3. 3. 3 Containing Quality ● About me – OSS Contributor – PHP Certified – Zend Certification Advisory Board – PHP-Fig voting member (IBM i Toolkit) – Consultant at Zend Technologies – Organizer SoFloPHP (South Florida) – Organizer SunshinePHP (Miami) – Long distance (ultra) runner – Photography Enthusiast – Judo Black Belt Instructor I am the PHP Ninja!!!
  4. 4. 4 Containing Quality ● Fan of iteration – Pretty much everything requires iteration to do well: ● Long distance running ● Judo ● Development ● Evading project managers ● Code Quality!
  5. 5. 5 Containing Quality ● How To Measure? – Not productive
  6. 6. 6 Does Your Code Measure Up? ● Why Measure? – Highlight bugs
  7. 7. 7 Does Your Code Measure Up? ● Why Measure? – Highlight bugs – Improve quality ● Easier onboarding ● Less reading, more writing ● Testable
  8. 8. 8 Does Your Code Measure Up? ● Why Measure? – Highlight bugs – Improve quality ● Easier onboarding ● Less reading, more writing ● Testable – Satisfied customers ● Faster development ● Less broken
  9. 9. 9 Does Your Code Measure Up? ● Why Measure? – Highlight bugs – Improve quality ● Easier onboarding ● Less reading, more writing ● Testable – Satisfied customers ● Faster development ● Less broken – Personal pride
  10. 10. 10 Containing Quality ● Why Measure? – Highlight bugs – Improve quality ● Easier onboarding ● Less reading, more writing ● Testable – Satisfied customers ● Faster development ● Less broken – Personal pride – Higher salary
  11. 11. 11 Containing Quality ● Bad Music – Not a song writer
  12. 12. 12 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity ● “The count of the number of linearly independent paths through the source code.” - wikipedia ● Decision points ● Less than 10 (personally less than 6)
  13. 13. 13 Does Your Code Measure Up? ● Cyclomatic Complexity Example
  14. 14. 14 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code ● Rule of 3
  15. 15. 15 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes ● Less than 1,000 lines ● Classes solve a (1) problem
  16. 16. 16 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class Complexity ● Less than 50
  17. 17. 17 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class complexity – Long methods ● Less than 100 (personally less than 20) ● Method should do one thing
  18. 18. 18 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class complexity – Long methods – Unused variables
  19. 19. 19 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class complexity – Long methods – Unused variables – Lack or overuse of comments ● Clear, concise, not explain bad code
  20. 20. 20 Does Your Code Measure Up? ● Comment Example
  21. 21. 21 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class complexity – Long methods – Unused variables – Lack or overuse of comments – Heavy global usage
  22. 22. 22 Does Your Code Measure Up? ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class complexity – Long methods – Unused variables – Lack or overuse of comments – Heavy global usage – Npath complexity ● Possible paths through code ● Less than 200 paths
  23. 23. 23 Containing Quality ● What To Measure? – Cyclomatic complexity – Duplicate code – Long classes – Class complexity – Long methods – Unused variables – Lack or overuse of comments – Heavy global usage – Npath complexity – Much, much, more ● Code smells
  24. 24. 24 Containing Quality ● Tools – PHPqatools.org – DEPRECATED – https://github.com/exakat/php-static-analysis-tools
  25. 25. 25 Containing Quality ● Tool Requirements – PHP – Dev environment – Special packages, extensions, dependencies – Consistent – Repeatable
  26. 26. 26 Containing Quality ● Docker Hub https://hub.docker.com/u/adamculp/
  27. 27. 27 Containing Quality ● Docker
  28. 28. 28 Containing Quality ● Containerized Tools – PHPLoc – PHPDepend – PHPMessDetector – PHPCopyPasteDetector – PHPMetrics – PHP_Codesniffer – PHPCompatibility – More… https://github.com/adamculp/php-code-quality https://hub.docker.com/u/adamculp/
  29. 29. 29 Containing Quality ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc
  30. 30. 30 Containing Quality ● PHPLoc Results
  31. 31. 31 Containing Quality ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend - https://pdepend.org/
  32. 32. 32 Containing Quality ● PHP_Depend Result – Graphs and XML output ANDC AHH NOP NOC NOM LOC CYCLO NOM CALLS FANOUT9891 96646 66812 395815 23359 342 3192 0.585 0.442 9.333 7.318 16.945 0.169 0.102 4.137 Generated by PHP_DependLow Average High
  33. 33. 33 Containing Quality ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector
  34. 34. 34 Containing Quality ● PHP Copy/Paste Detector Result
  35. 35. 35 Containing Quality ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector ● PHP Mess Detector – Codesize
  36. 36. 36 Containing Quality ● PHP Mess Detector Result (codesize)
  37. 37. 37 Containing Quality ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector ● PHP Mess Detector – Codesize – Unused
  38. 38. 38 Containing Quality ● Tools – PHPqatools.org – DEPRECATED ● PHPLoc ● PHP_Depend ● PHP Copy/Paste Detector ● PHP Mess Detector – Codesize – Unused ● PHP Dead Code Detector – Searches for code no longer used
  39. 39. 39 Containing Quality ● Tools – PHPqatools.org – DEPRECATED – PHPMetrics ● http://phpmetrics.org
  40. 40. 40 Containing Quality ● PHPMetrics Results
  41. 41. 41 Containing Quality ● Tools – PHPqatools.org – DEPRECATED – PHPMetrics – PHP_Codesniffer ● Create rules/sniffs to ensure standards are followed ● From CLI, IDE, or via SCM hooks
  42. 42. 42 Containing Quality ● Tools – PHPqatools.org – DEPRECATED – PHPMetrics – PHP_Codesniffer ● Create rules/sniffs to ensure standards are followed ● From CLI, IDE, or via SCM hooks
  43. 43. 43 Containing Quality ● Tools – PHPqatools.org – DEPRECATED – PHPMetrics – PHP_Codesniffer – PHPCompatibility
  44. 44. 44 Containing Quality ● Tools – PHPqatools.org – DEPRECATED – PHPMetrics – PHP_Codesniffer – PHPCompatibility
  45. 45. 45 Containing Quality ● Conclusion – Measure all the things! – Don't fear results, share them – Reduce complexity – Leave code cleaner than you got it – Learn to “smell” problems – Use refactoring to fix shortcomings – Love iteration!
  46. 46. 46 ● Thank you! – http://phpqatools.org https://github.com/exakat/php-static-analysis-tools – http://phpmetrics.org – https://github.com/adamculp/php-code-quality – http://zend.com – Please rate Adam Culp http://www.geekyboy.com http://RunGeekRadio.com Twitter @adamculp

×