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 |
||
11 | class SignalDispatcherFactory |
||
12 | { |
||
13 | /** |
||
14 | * Relative namespace for internal signals. |
||
15 | */ |
||
16 | const RELATIVE_SIGNAL_NAMESPACE = 'eZ\\Publish\\Core\\SignalSlot\\Signal'; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $signalDispatcherClass; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $signalSlotMap = []; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $searchEngineAlias; |
||
32 | |||
33 | /** |
||
34 | * SignalDispatcherFactory constructor. |
||
35 | * |
||
36 | * @param string $signalDispatcherClass |
||
37 | * @param $searchEngineAlias |
||
38 | */ |
||
39 | public function __construct( |
||
46 | |||
47 | /** |
||
48 | * Get current search engine alias. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getSearchEngineAlias() |
||
56 | |||
57 | /** |
||
58 | * Bulk add all signal slots if needed for a search engine. |
||
59 | * |
||
60 | * @param string $searchEngineAlias |
||
61 | * @param array $searchEngineSignalSlots [signal => array(slot1, slot2, ...)] |
||
62 | */ |
||
63 | public function addSlotsForSearchEngine($searchEngineAlias, array $searchEngineSignalSlots) |
||
78 | |||
79 | /** |
||
80 | * Build SignalDispatcher for SignalSlots. |
||
81 | * |
||
82 | * @return \eZ\Publish\Core\SignalSlot\SignalDispatcher |
||
83 | */ |
||
84 | public function buildSignalDispatcher() |
||
88 | } |
||
89 |
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.