Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
7 | class MemoryContributor implements HealthContributor |
||
8 | { |
||
9 | 1 | public function run(): array |
|
16 | |||
17 | /** |
||
18 | * Return the memory free in kbytes |
||
19 | */ |
||
20 | 1 | private function getMemoryFree(): int |
|
24 | |||
25 | /** |
||
26 | * Return the maximum memory allocated to php in kbytes |
||
27 | */ |
||
28 | 1 | private function getMemoryAllocated(): int |
|
32 | |||
33 | /** |
||
34 | * Return the memory usage in kbytes |
||
35 | */ |
||
36 | 1 | private function getMemoryUsage(): int |
|
40 | |||
41 | /* |
||
42 | * Source https://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes |
||
43 | */ |
||
44 | View Code Duplication | private function formatBytes($bytes, $precision = 2): string |
|
55 | } |
||
56 |