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 |
||
9 | View Code Duplication | abstract class SimpleFactoryPlugin implements SimpleFactoryPluginInterface |
|
|
|||
10 | { |
||
11 | /** |
||
12 | * @var bool |
||
13 | */ |
||
14 | private $registered; |
||
15 | |||
16 | /** |
||
17 | * @override |
||
18 | * @inheritDoc |
||
19 | */ |
||
20 | 4 | public function registerPlugin(SimpleFactoryInterface $factory) |
|
38 | |||
39 | /** |
||
40 | * @override |
||
41 | * @inheritDoc |
||
42 | */ |
||
43 | 3 | public function unregisterPlugin(SimpleFactoryInterface $factory) |
|
53 | |||
54 | /** |
||
55 | * Define how plugin should be registered. |
||
56 | * |
||
57 | * @param SimpleFactoryInterface $factory |
||
58 | */ |
||
59 | protected function register(SimpleFactoryInterface $factory) |
||
61 | |||
62 | /** |
||
63 | * Define how plugin should be unregistered. |
||
64 | * |
||
65 | * @param SimpleFactoryInterface $factory |
||
66 | */ |
||
67 | protected function unregister(SimpleFactoryInterface $factory) |
||
69 | |||
70 | /** |
||
71 | * @param Error|Exception $ex |
||
72 | * @throws ExecutionException |
||
73 | */ |
||
74 | 1 | private function throwException($ex) |
|
78 | } |
||
79 |
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.