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 declare(strict_types=1); |
||
21 | final class Element extends Node |
||
22 | { |
||
23 | /** |
||
24 | * Constructor. |
||
25 | * |
||
26 | * @param \Twig\Node\Expression\AbstractExpression $name Name. |
||
27 | * @param \Twig\Node\Expression\AbstractExpression $data Data. |
||
28 | * @param \Twig\Node\Expression\AbstractExpression $options Options. |
||
29 | * @param string $lineno Linenumber. |
||
30 | * @param string $tag Tag. |
||
31 | */ |
||
32 | View Code Duplication | public function __construct( |
|
58 | |||
59 | /** |
||
60 | * Compile node. |
||
61 | * |
||
62 | * @param \Twig\Compiler $compiler Compiler. |
||
63 | * |
||
64 | */ |
||
65 | public function compile(Compiler $compiler) |
||
83 | } |
||
84 |
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.