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 |
||
14 | abstract class Addons extends Extend\Utils\Loader { |
||
15 | |||
16 | /** |
||
17 | * Load the list of all items |
||
18 | */ |
||
19 | |||
20 | protected function loadItemsAll() : array { |
||
33 | |||
34 | /** |
||
35 | * Load the list of installed items |
||
36 | */ |
||
37 | |||
38 | protected function loadItemsInstalled() : array { |
||
51 | |||
52 | /** |
||
53 | * Constructor |
||
54 | */ |
||
55 | |||
56 | public function __construct(bool $load_all = true) { |
||
62 | |||
63 | /** |
||
64 | * Install or uninstall an item |
||
65 | * |
||
66 | * @param $value : if set to true the item will be installed, otherwise uninstalled |
||
67 | * |
||
68 | * @return bool : true on success or false on failure |
||
69 | */ |
||
70 | |||
71 | public function install(string $name, bool $value = true) : bool { |
||
92 | } |
||
93 | } |
||
94 |
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.