Code Analysis with PHP Metrics

Code Analysis with PHP Metrics

6834447bdbca70cd2390adc690c3b4f1?s=128

Chris Gmyr

July 27, 2017
Tweet

Transcript

  1. Code Analysis with PHP Metrics

  2. Presented by Chris Gmyr @cmgmyr

  3. Installation composer global require phpmetrics/phpmetrics

  4. Generate Report phpmetrics --report-html=myreport /path/of/src

  5. Laravel git clone git@github.com:laravel/laravel.git phpmetrics --report-html=laravel_metrics laravel

  6. None
  7. None
  8. None
  9. What Are We Going to Learn? 4 Maintainability 4 Violations

    4 Complexity 4 Relationships
  10. But First, Some Vocabulary! !

  11. Cyclomatic Complexity The cyclomatic complexity of a section of source

    code is the number of linearly independent paths within it. 4 If the source code contained no control flow statements (conditionals or decision points), the complexity would be 1. 4 One IF statement = two paths through the code, complexity would be 2. 4 Two nested single-condition IFs, or one IF with two conditions, would produce a complexity of 3. https://en.wikipedia.org/wiki/Cyclomatic_complexity
  12. None
  13. More Conditionals & Statements = More Complex

  14. Lower Score is Better!

  15. Halstead Complexity Measures Observation that metrics of the software should

    reflect the implementation or expression of algorithms in different languages, but be independent of their execution on a specific platform. https://en.wikipedia.org/wiki/ Halstead_complexity_measures http://www.verifysoft.com/en_halstead_metrics.html
  16. None
  17. Lower Score is Better!

  18. Maintainability Index Provides a score between 0 to 118. Halstead's

    metrics, LOC and Cyclomatic complexity number. General scores: 4 <64: low maintainability. The project has probably technical debt. 4 65-84: medium maintainability. The project has problems, but nothing really serious. 4 >85: high maintainability. The project is probably good.
  19. Higher Score is Better!

  20. Let's Explore!

  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. None
  28. None
  29. None
  30. None
  31. None
  32. None
  33. None
  34. None
  35. Violations

  36. None
  37. None
  38. Size & Volume

  39. None
  40. Complexity & Defects

  41. None
  42. Object Oriented Metrics

  43. None
  44. Object Relations

  45. None
  46. Coupling

  47. None
  48. None
  49. Takeaways 1. More Classes 2. Smaller Classes 3. Simpler Classes

    4. Loosely Coupled Classes
  50. Thank you!

  51. Say "Hi"! twitter.com/cmgmyr github.com/cmgmyr chrisgmyr.com