Upgrade to Pro — share decks privately, control downloads, hide ads and more …

コードを計測することで捉える問題点 / phpcondo2024

コードを計測することで捉える問題点 / phpcondo2024

PHPカンファレンス北海道2024の登壇資料です。
https://phpcon.hokkaido.jp/

blue_goheimochi

January 13, 2024
Tweet

More Decks by blue_goheimochi

Other Decks in Technology

Transcript

  1. 5 • : phpcpd • Copy/Paste Detector (CPD) for PHP

    code. • 2023 1 • • Don t Repeat Yourself •
  2. 6 phpcpd 6.0.3 by Sebastian Bergmann. Found 184 clones with

    9893 duplicated lines in 142 files: - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:166-524 (358 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:170-528 ~~~~~~~~~~ - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:321-561 (240 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:334-574 ~~~~~~~~~~~ - /app/xxxxxx/controllers/xxxxxx.php:909-1084 (175 lines) /app/xxxxxx/controllers/xxxxxx.php:1247-1422 ~~~~~~~~~~ 8.41% duplicated lines out of 112932 total lines of code. Average size of duplication is 54 lines, largest clone has 358 of lines 184 142 9,893
  3. 7 phpcpd 6.0.3 by Sebastian Bergmann. Found 184 clones with

    9893 duplicated lines in 142 files: - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:166-524 (358 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:170-528 ~~~~~~~~~~ - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:321-561 (240 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:334-574 ~~~~~~~~~~~ - /app/xxxxxx/controllers/xxxxxx.php:909-1084 (175 lines) /app/xxxxxx/controllers/xxxxxx.php:1247-1422 ~~~~~~~~~~ 8.41% duplicated lines out of 112932 total lines of code. Average size of duplication is 54 lines, largest clone has 358 of lines View
  4. 8 phpcpd 6.0.3 by Sebastian Bergmann. Found 184 clones with

    9893 duplicated lines in 142 files: - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:166-524 (358 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:170-528 ~~~~~~~~~~ - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:321-561 (240 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:334-574 ~~~~~~~~~~~ - /app/xxxxxx/controllers/xxxxxx.php:909-1084 (175 lines) /app/xxxxxx/controllers/xxxxxx.php:1247-1422 ~~~~~~~~~~ 8.41% duplicated lines out of 112932 total lines of code. Average size of duplication is 54 lines, largest clone has 358 of lines Fat
  5. 9 phpcpd 6.0.3 by Sebastian Bergmann. Found 184 clones with

    9893 duplicated lines in 142 files: - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:166-524 (358 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:170-528 ~~~~~~~~~~ - /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:321-561 (240 lines) /app/xxxxxx/xxxxxx/xxxxxx/xxxxxx.php:334-574 ~~~~~~~~~~~ - /app/xxxxxx/controllers/xxxxxx.php:909-1084 (175 lines) /app/xxxxxx/controllers/xxxxxx.php:1247-1422 ~~~~~~~~~~ 8.41% duplicated lines out of 112932 total lines of code. Average size of duplication is 54 lines, largest clone has 358 of lines 112,932 8.41% 54 358
  6. 12 • : terryyin/lizard • Lizard is an extensible Cyclomatic

    Complexity Analyzer for many programming languages(PHP Python ) • • • • if/else, for, switch •
  7. 14 • : terryyin/lizard • Lizard is an extensible Cyclomatic

    Complexity Analyzer for many programming languages(PHP Python ) • • • if/else, for, switch • ========================================================================================= !!!! Warnings (cyclomatic_complexity > 15 or length > 1000 or parameter_count > 100) !!!! ================================================ NLOC CCN token PARAM length location ------------------------------------------------ 247 63 2436 0 353 aaaaAction@41-393@./xxxxx/controllers/zzzzController.php 139 41 1272 0 202 bbbbAction@625-826@./xxxxx/controllers/zzzzController.php 124 39 1018 0 161 ccccAction@77-237@./xxxxx/controllers/zzzzController.php 81 37 351 1 84 xxxx@840-923@./xxxx/xxxx/Controller/xxxx/Abstract.php 152 37 1086 0 197 xxxxAction@21-217@./xxxx/xxxx/xxxx/xxxxController.php 143 36 1110 0 197 xxxxAction@740-936@./xxxx/xxxx/xxxxController.php 150 35 1516 0 223 xxxxAction@33-255@./xxxx/controllers/xxxxController.php 63 34 741 1 72 xxxx@16-87@./xxxx/xxxx/xxxx/xxxx/xxxx/xxxx.php 81 34 917 0 106 aaaaAction@229-334@./yyyy/controllers/yyyyController.php 110 31 1071 0 143 xxxxAction@20-162@./xxxx/controllers/xxxxController.php 75 30 753 0 108 bbbb@79-186@./xxxx/controllers/yyyyController.php 97 29 926 0 127 ccccAction@609-735@./xxxx/controllers/yyyyController.php ========================================================================================== Total nloc Avg.NLOC AvgCCN Avg.token Fun Cnt Warning cnt Fun Rt nloc Rt ------------------------------------------------------------------------------------------ 33248 16.3 2.3 104.2 1743 11 0.01 0.05 63 70%
  8. 15 • : terryyin/lizard • Lizard is an extensible Cyclomatic

    Complexity Analyzer for many programming languages(PHP Python ) • • • if/else, for, switch • ========================================================================================= !!!! Warnings (cyclomatic_complexity > 15 or length > 1000 or parameter_count > 100) !!!! ================================================ NLOC CCN token PARAM length location ------------------------------------------------ 247 63 2436 0 353 aaaaAction@41-393@./xxxxx/controllers/zzzzController.php 139 41 1272 0 202 bbbbAction@625-826@./xxxxx/controllers/zzzzController.php 124 39 1018 0 161 ccccAction@77-237@./xxxxx/controllers/zzzzController.php 81 37 351 1 84 xxxx@840-923@./xxxx/xxxx/Controller/xxxx/Abstract.php 152 37 1086 0 197 xxxxAction@21-217@./xxxx/xxxx/xxxx/xxxxController.php 143 36 1110 0 197 xxxxAction@740-936@./xxxx/xxxx/xxxxController.php 150 35 1516 0 223 xxxxAction@33-255@./xxxx/controllers/xxxxController.php 63 34 741 1 72 xxxx@16-87@./xxxx/xxxx/xxxx/xxxx/xxxx/xxxx.php 81 34 917 0 106 aaaaAction@229-334@./yyyy/controllers/yyyyController.php 110 31 1071 0 143 xxxxAction@20-162@./xxxx/controllers/xxxxController.php 75 30 753 0 108 bbbb@79-186@./xxxx/controllers/yyyyController.php 97 29 926 0 127 ccccAction@609-735@./xxxx/controllers/yyyyController.php ========================================================================================== Total nloc Avg.NLOC AvgCCN Avg.token Fun Cnt Warning cnt Fun Rt nloc Rt ------------------------------------------------------------------------------------------ 33248 16.3 2.3 104.2 1743 11 0.01 0.05 3
  9. 19 • : phpmd unusedcode • • • • •

    <?php class Sample { private static $start = 1; private $end = 2; private $piyo = 3; public function addOne() { $item = 1; return $this->piyo++; } private function execute($text) { } }
  10. 20 • : phpmd unusedcode • • • • •

    <?php class Sample { private static $start = 1; private $end = 2; private $piyo = 3; public function addOne() { $item = 1; return $this->piyo++; } private function execute($text) { } }
  11. 21 • : phpmd unusedcode • • • • •

    FILE: /app/sample.php ---------------------- 5 | VIOLATION | Avoid unused private fields such as '$start'. 6 | VIOLATION | Avoid unused private fields such as '$end'. 11 | VIOLATION | Avoid unused local variables such as '$item'. 15 | VIOLATION | Avoid unused private methods such as 'execute'. 15 | VIOLATION | Avoid unused parameters such as '$text'.
  12. 23 1) sample.php:1 ---------- begin diff ---------- @@ @@ class

    Sample { - private static int $start = 1; - private $end = 2; private $piyo = 3; public function addOne() { - $item = 1; return $this->piyo++; - } - - private function execute($text) - { } } ----------- end diff ----------- Rectorの場合
  13. 24 <?php class Sample { private $piyo = 3; public

    function addOne() { return $this->piyo++; } } <?php class Sample { private static $start = 1; private $end = 2; private $piyo = 3; public function addOne() { $item = 1; return $this->piyo++; } private function execute($text) { } } Rectorの場合
  14. 29 • 12 • phpcpd, lizard, churn-php, phpmd, phpstan, rector,

    phpmetrics, composer-unused, phpmnd, phpcs, php-cs-fixer, phpinsights • • 800MB • ro
  15. 37

  16. 38

  17. 40

  18. 58

  19. 61 • The core assumption behind GQM is simple:to measure

    something well, you must understand why you re measuring • • Improve system availability from the users point of view. • Decrease the development time for new microservices from the product managers viewpoint. • Reduce technical debt in the architecture from the perspective of software developers. • Reduce the number of bugs being released into production. • Detect more problems in production before our users do. • Improve the machine learning model s accuracy from the users viewpoint. • Make better design decisions in the architecture from the development team s perspective.
  20. 71

  21. 72