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 |
||
23 | class Manager implements ManagerInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var \HDNET\Importr\Domain\Repository\ImportRepository |
||
28 | */ |
||
29 | protected $importRepository; |
||
30 | |||
31 | /** |
||
32 | * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher |
||
33 | */ |
||
34 | protected $signalSlotDispatcher; |
||
35 | |||
36 | /** |
||
37 | * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager |
||
38 | */ |
||
39 | protected $persistenceManager; |
||
40 | |||
41 | /** |
||
42 | * @var \TYPO3\CMS\Extbase\Object\ObjectManager |
||
43 | */ |
||
44 | protected $objectManager; |
||
45 | |||
46 | /** |
||
47 | * @var \HDNET\Importr\Processor\Configuration |
||
48 | */ |
||
49 | protected $configuration; |
||
50 | |||
51 | /** |
||
52 | * @var \HDNET\Importr\Processor\Resource |
||
53 | */ |
||
54 | protected $resource; |
||
55 | |||
56 | public function __construct( |
||
71 | |||
72 | /** |
||
73 | * Update Interval |
||
74 | * |
||
75 | * @var int |
||
76 | */ |
||
77 | protected $updateInterval = 1; |
||
78 | |||
79 | /** |
||
80 | * run the Importr |
||
81 | */ |
||
82 | public function runImports() |
||
93 | |||
94 | /** |
||
95 | * Get the preview |
||
96 | * |
||
97 | * @param string $filepath |
||
98 | * @param \HDNET\Importr\Domain\Model\Strategy $strategy |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | public function getPreview(Strategy $strategy, $filepath) |
||
123 | |||
124 | /** |
||
125 | * Magic Runner |
||
126 | * |
||
127 | * @param \HDNET\Importr\Domain\Model\Import $import |
||
128 | */ |
||
129 | protected function runImport(Import $import) |
||
148 | |||
149 | /** |
||
150 | * @param \HDNET\Importr\Domain\Model\Import $import |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | protected function initializeResourcesByImport(Import $import) |
||
158 | |||
159 | /** |
||
160 | * @param \HDNET\Importr\Domain\Model\Strategy $strategy |
||
161 | * @param string $filepath |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | View Code Duplication | protected function initializeResources(Strategy $strategy, $filepath) |
|
177 | |||
178 | /** |
||
179 | * @param \HDNET\Importr\Domain\Model\Import $import |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | View Code Duplication | protected function initializeTargets(Import $import) |
|
197 | |||
198 | /** |
||
199 | * @param \HDNET\Importr\Domain\Model\Import $import |
||
200 | */ |
||
201 | protected function teardownTargets(Import $import) |
||
212 | |||
213 | /** |
||
214 | * @param int $interval |
||
215 | */ |
||
216 | public function setUpdateInterval($interval) |
||
220 | |||
221 | /** |
||
222 | * @return int |
||
223 | */ |
||
224 | public function getUpdateInterval() |
||
228 | |||
229 | /** |
||
230 | * @param string $name |
||
231 | * @param Import $import |
||
232 | */ |
||
233 | protected function emitSignal($name, Import $import) |
||
241 | } |
||
242 |
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.