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 |
||
10 | trait Macroable |
||
11 | { |
||
12 | protected static $macros = []; |
||
13 | |||
14 | /** |
||
15 | * Register a custom macro. |
||
16 | * |
||
17 | * @param string $name |
||
18 | * @param object|callable $macro |
||
19 | */ |
||
20 | public static function macro(string $name, $macro) |
||
24 | |||
25 | /** |
||
26 | * Mix another object into the class. |
||
27 | * |
||
28 | * @param object $mixin |
||
29 | */ |
||
30 | public static function mixin($mixin) |
||
42 | |||
43 | public static function hasMacro(string $name): bool |
||
47 | |||
48 | View Code Duplication | public static function __callStatic($method, $parameters) |
|
62 | |||
63 | View Code Duplication | public function __call($method, $parameters) |
|
77 | } |
||
78 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.