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 |
||
8 | class AliasResolver |
||
9 | { |
||
10 | use AppNamespaceDetectorTrait; |
||
11 | |||
12 | /** |
||
13 | * @var static |
||
14 | */ |
||
15 | protected static $instance; |
||
16 | |||
17 | /** |
||
18 | * @param string $app_path |
||
19 | * @param array $addons |
||
20 | * @param array $aliases |
||
21 | */ |
||
22 | 2 | View Code Duplication | public static function register($app_path, array $addons, array $aliases) |
30 | |||
31 | /** |
||
32 | */ |
||
33 | 2 | public static function unregister() |
|
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $addons; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $globalClassAliases; |
||
49 | |||
50 | /** |
||
51 | * The constructor. |
||
52 | * |
||
53 | * @param string $app_path |
||
54 | * @param array $addons |
||
55 | * @param array $aliases |
||
56 | */ |
||
57 | 3 | public function __construct($app_path, array $addons, array $aliases) |
|
62 | |||
63 | /** |
||
64 | * Make addon instance for application namespace. |
||
65 | * |
||
66 | * @param string $path |
||
67 | * |
||
68 | * @return static |
||
69 | */ |
||
70 | 3 | protected function makeAppAddon($path) |
|
78 | |||
79 | /** |
||
80 | * @param string $className |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | 1 | public function load($className) |
|
130 | } |
||
131 |
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.