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 |
||
19 | class LogicalAndToken implements TokenInterface |
||
20 | { |
||
21 | private $tokens = array(); |
||
22 | |||
23 | /** |
||
24 | * @param array $arguments exact values or tokens |
||
25 | */ |
||
26 | View Code Duplication | public function __construct(array $arguments) |
|
35 | |||
36 | /** |
||
37 | * Scores maximum score from scores returned by tokens for this argument if all of them score. |
||
38 | * |
||
39 | * @param $argument |
||
40 | * |
||
41 | * @return bool|int |
||
42 | */ |
||
43 | public function scoreArgument($argument) |
||
60 | |||
61 | /** |
||
62 | * Returns false. |
||
63 | * |
||
64 | * @return boolean |
||
65 | */ |
||
66 | public function isLast() |
||
70 | |||
71 | /** |
||
72 | * Returns string representation for token. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | public function __toString() |
||
80 | } |
||
81 |
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.