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 |
||
12 | class NewExpression extends StaticClassExpression |
||
13 | { |
||
14 | /** |
||
15 | * @var ArgumentExpression[] |
||
16 | */ |
||
17 | private $arguments; |
||
18 | |||
19 | public function __construct(Expression $class, array $arguments = []) |
||
25 | |||
26 | /** |
||
27 | * @return Expression[] |
||
28 | */ |
||
29 | public function getArguments() |
||
33 | |||
34 | public function traverse(ExpressionWalker $walker) |
||
38 | |||
39 | /** |
||
40 | * @param Expression $class |
||
41 | * @param ArgumentExpression[] $arguments |
||
42 | * |
||
43 | * @return NewExpression |
||
44 | */ |
||
45 | View Code Duplication | public function update(Expression $class, array $arguments = []) |
|
55 | |||
56 | protected function updateClassValue(Expression $class) |
||
60 | |||
61 | protected function compileCode(&$code) |
||
71 | |||
72 | protected function dataToSerialize() |
||
76 | |||
77 | protected function unserializeData($data) |
||
81 | |||
82 | public function __clone() |
||
87 | } |
||
88 |
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.