Slide 1

Slide 1 text

PHP 2024 2024.01.13 Yuta Ohashi

Slide 2

Slide 2 text

/ @blue_goheimochi , , , , PUBG MOBILE,

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

4 • • • • • • etc...

Slide 5

Slide 5 text

5 • : phpcpd • Copy/Paste Detector (CPD) for PHP code. • 2023 1 • • Don t Repeat Yourself •

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

10 • : 112,932 • : 8.41% • : 9,893 • : 184 • 規 : 142

Slide 11

Slide 11 text

11 • • • • • •

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

13 10 25% 30 40% 50 70% 75 98%

Slide 14

Slide 14 text

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%

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

16 • ( ): 69,946 • CCN: 2.8 • CCN • :4,518

Slide 17

Slide 17 text

17 • • • • •

Slide 18

Slide 18 text

18 • : phpmd unusedcode • • • • •

Slide 19

Slide 19 text

19 • : phpmd unusedcode • • • • • piyo++; } private function execute($text) { } }

Slide 20

Slide 20 text

20 • : phpmd unusedcode • • • • • piyo++; } private function execute($text) { } }

Slide 21

Slide 21 text

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'.

Slide 22

Slide 22 text

22 • • • • • • Rector, PHPStan

Slide 23

Slide 23 text

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の場合

Slide 24

Slide 24 text

24 piyo++; } } piyo++; } private function execute($text) { } } Rectorの場合

Slide 25

Slide 25 text

25 • : PHPStan, Psalm • (= ) • • •

Slide 26

Slide 26 text

26 • : PHP CSFixer, PHP CodeSni er • PSR-12 PSR-2 • •

Slide 27

Slide 27 text

27 🙋 🙋 🙋

Slide 28

Slide 28 text

28 % git clone [email protected]:blue-goheimochi/php-metrics-tools.git % cd php-metrics-tools % make build % export TARGET_DIR=/Path/To/Target/Dir % make phpcpd

Slide 29

Slide 29 text

29 • 12 • phpcpd, lizard, churn-php, phpmd, phpstan, rector, phpmetrics, composer-unused, phpmnd, phpcs, php-cs-fixer, phpinsights • • 800MB • ro

Slide 30

Slide 30 text

30 • : Software metric • • by

Slide 31

Slide 31 text

31 • • • • : • ... • 24 •

Slide 32

Slide 32 text

32 • • 1 • • •

Slide 33

Slide 33 text

なぜコード計測をして問題点を捉えたいのか??

Slide 34

Slide 34 text

34 • • • • • •

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

36 • • • • • • etc...etc...etc... • 🐌

Slide 37

Slide 37 text

37

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

39 (legacy)

Slide 40

Slide 40 text

40

Slide 41

Slide 41 text

41 3 • • •

Slide 42

Slide 42 text

42 3 • • • •

Slide 43

Slide 43 text

43 3 • • • • •

Slide 44

Slide 44 text

44 3 • • • • • • • •

Slide 45

Slide 45 text

45 3 • • • •

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

47 3 • • •

Slide 48

Slide 48 text

48 3 • • • •

Slide 49

Slide 49 text

49 3 • • • • • •

Slide 50

Slide 50 text

50 3 • • • • • • •

Slide 51

Slide 51 text

51 3 • • • • •

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

53 • • • • •

Slide 54

Slide 54 text

54 • • • • • •

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

56 • • • • • • etc...

Slide 57

Slide 57 text

57 • • • : • : • •

Slide 58

Slide 58 text

58

Slide 59

Slide 59 text

59 • • 70% • SHS

Slide 60

Slide 60 text

60 • GQM Goal Question Metric •

Slide 61

Slide 61 text

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.

Slide 62

Slide 62 text

62 How • • • • ex) •

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

64 • • • • Four Keys

Slide 65

Slide 65 text

65 • : Git • Git •

Slide 66

Slide 66 text

66 • : Google Analytics • • •

Slide 67

Slide 67 text

67 • : New Relic, Datadog, Mackerel, Sentry • APM • • •

Slide 68

Slide 68 text

68 Four Keys • For keys • • •

Slide 69

Slide 69 text

69 • • • •

Slide 70

Slide 70 text

70 • • • •

Slide 71

Slide 71 text

71

Slide 72

Slide 72 text

72

Slide 73

Slide 73 text

まとめ

Slide 74

Slide 74 text

74 • • • • • • •