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 DefaultCaseViewHelper extends AbstractViewHelper implements NodeFilterInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var boolean |
||
28 | */ |
||
29 | protected $escapeOutput = false; |
||
30 | |||
31 | /** |
||
32 | * @return string the contents of this view helper if no other "Case" view helper of the surrounding switch view helper matches |
||
33 | * @throws ViewHelper\Exception |
||
34 | * @api |
||
35 | */ |
||
36 | public function render() |
||
44 | |||
45 | /** |
||
46 | * DefaultCase ViewHelper disallows any whitespace-only text nodes as children. This means that |
||
47 | * when rendered, the output of the node excludes any whitespace before and after the |
||
48 | * "real" output. |
||
49 | * |
||
50 | * @param NodeInterface $node |
||
51 | * @return bool |
||
52 | */ |
||
53 | View Code Duplication | public function allowsChildNodeType(NodeInterface $node): bool |
|
60 | |||
61 | /** |
||
62 | * @param string $argumentsName |
||
63 | * @param string $closureName |
||
64 | * @param string $initializationPhpCode |
||
65 | * @param ViewHelperNode $node |
||
66 | * @param TemplateCompiler $compiler |
||
67 | * @return string |
||
68 | */ |
||
69 | public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler) |
||
73 | } |
||
74 |
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.