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 |
||
22 | class ThenViewHelper extends AbstractViewHelper implements NodeFilterInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var boolean |
||
27 | */ |
||
28 | protected $escapeOutput = false; |
||
29 | |||
30 | /** |
||
31 | * Just render everything. |
||
32 | * |
||
33 | * @return string the rendered string |
||
34 | * @api |
||
35 | */ |
||
36 | public function render() |
||
40 | |||
41 | /** |
||
42 | * Condition ViewHelpers disallow child nodes that consist purely of whitespace, |
||
43 | * thus avoiding whitespace in output inside f:if structures but not inside any |
||
44 | * f:then or f:else nodes. |
||
45 | * |
||
46 | * @param NodeInterface $node |
||
47 | * @return bool |
||
48 | */ |
||
49 | View Code Duplication | public function allowsChildNodeType(NodeInterface $node): bool |
|
56 | |||
57 | /** |
||
58 | * @param string $argumentsName |
||
59 | * @param string $closureName |
||
60 | * @param string $initializationPhpCode |
||
61 | * @param ViewHelperNode $node |
||
62 | * @param TemplateCompiler $compiler |
||
63 | * @return string |
||
64 | */ |
||
65 | public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler) |
||
69 | } |
||
70 |
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.