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 |
||
24 | View Code Duplication | class MultiCallTransportEvent extends AbstractEvent |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * @var MultiCallQueueInterface |
||
28 | */ |
||
29 | protected $queue; |
||
30 | |||
31 | /** |
||
32 | * @var mixed |
||
33 | */ |
||
34 | protected $results; |
||
35 | |||
36 | /** |
||
37 | * @param RemoteAdapterInterface $remoteAdapter |
||
38 | * @param MultiCallQueueInterface $queue |
||
39 | * @param mixed $results |
||
40 | */ |
||
41 | public function __construct(RemoteAdapterInterface $remoteAdapter, MultiCallQueueInterface $queue, $results = null) |
||
47 | |||
48 | /** |
||
49 | * @param MultiCallQueueInterface $queue |
||
50 | */ |
||
51 | public function setQueue(MultiCallQueueInterface $queue) |
||
55 | |||
56 | /** |
||
57 | * @return MultiCallQueueInterface |
||
58 | */ |
||
59 | public function getQueue() |
||
63 | |||
64 | /** |
||
65 | * @param array $results |
||
66 | */ |
||
67 | public function setResults($results) |
||
71 | |||
72 | /** |
||
73 | * @return mixed |
||
74 | */ |
||
75 | public function getResults() |
||
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.