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 | class ExecutorPool |
||
10 | { |
||
11 | /** |
||
12 | * @var ExecutorInterface[] |
||
13 | */ |
||
14 | protected $executors = []; |
||
15 | |||
16 | /** |
||
17 | * @param string $action |
||
18 | * |
||
19 | * @return bool |
||
20 | */ |
||
21 | public function hasExecutor($action) |
||
25 | |||
26 | /** |
||
27 | * Add an executor. |
||
28 | * |
||
29 | * @param ExecutorInterface $executor |
||
30 | * |
||
31 | * @throws InvalidArgumentException |
||
32 | */ |
||
33 | View Code Duplication | public function addExecutor(ExecutorInterface $executor) |
|
48 | |||
49 | /** |
||
50 | * Returns a registered executor for given action. |
||
51 | * |
||
52 | * @param string $action |
||
53 | * |
||
54 | * @return ExecutorInterface |
||
55 | * |
||
56 | * @throws OutOfBoundsException |
||
57 | */ |
||
58 | View Code Duplication | public function getExecutor($action) |
|
71 | |||
72 | /** |
||
73 | * @return ExecutorInterface[] |
||
74 | */ |
||
75 | public function getExecutors() |
||
79 | } |
||
80 |
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.