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 |
||
10 | class HeaderFooterWrapper extends BaseWrapper |
||
11 | { |
||
12 | /** |
||
13 | * @var SheetWrapper |
||
14 | */ |
||
15 | protected $sheetWrapper; |
||
16 | |||
17 | /** |
||
18 | * @var null|HeaderFooter |
||
19 | */ |
||
20 | protected $object; |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $alignmentAttributes; |
||
25 | |||
26 | /** |
||
27 | * HeaderFooterWrapper constructor. |
||
28 | * |
||
29 | * @param array $context |
||
30 | * @param \Twig_Environment $environment |
||
31 | * @param SheetWrapper $sheetWrapper |
||
32 | */ |
||
33 | public function __construct(array $context, \Twig_Environment $environment, SheetWrapper $sheetWrapper) |
||
42 | |||
43 | /** |
||
44 | * @param string $type |
||
45 | * @param array $properties |
||
46 | * |
||
47 | * @throws \InvalidArgumentException |
||
48 | * @throws \LogicException |
||
49 | * @throws \RuntimeException |
||
50 | */ |
||
51 | public function start(string $type, array $properties = []) |
||
70 | |||
71 | public function end() |
||
117 | |||
118 | /** |
||
119 | * @param string $type |
||
120 | * @param array $properties |
||
121 | * |
||
122 | * @throws \InvalidArgumentException |
||
123 | */ |
||
124 | public function startAlignment(string $type, array $properties = []) |
||
143 | |||
144 | /** |
||
145 | * @param string $value |
||
146 | * |
||
147 | * @throws \InvalidArgumentException |
||
148 | */ |
||
149 | public function endAlignment($value) |
||
173 | |||
174 | /** |
||
175 | * @return null|HeaderFooter |
||
176 | */ |
||
177 | public function getObject() |
||
181 | |||
182 | /** |
||
183 | * @param null|HeaderFooter $object |
||
184 | */ |
||
185 | public function setObject(HeaderFooter $object = null) |
||
189 | |||
190 | /** |
||
191 | * @return array |
||
192 | */ |
||
193 | public function getAlignmentAttributes(): array |
||
197 | |||
198 | /** |
||
199 | * @param array $alignmentAttributes |
||
200 | */ |
||
201 | public function setAlignmentAttributes(array $alignmentAttributes) |
||
205 | |||
206 | /** |
||
207 | * @return array |
||
208 | */ |
||
209 | protected function configureMappings(): array |
||
216 | } |
||
217 |
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.