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 |
||
20 | class Union implements StatementInterface, NodeInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var array|Select[] |
||
24 | */ |
||
25 | private $selects; |
||
26 | |||
27 | /** |
||
28 | * Union constructor. |
||
29 | * @param Select[] $selects |
||
30 | */ |
||
31 | public function __construct(array $selects) |
||
35 | |||
36 | /** |
||
37 | * @param MoufManager $moufManager |
||
38 | * |
||
39 | * @return MoufInstanceDescriptor |
||
40 | */ |
||
41 | View Code Duplication | public function toInstanceDescriptor(MoufManager $moufManager) |
|
48 | |||
49 | /** |
||
50 | * Configure the $instanceDescriptor describing this object (it must already exist as a Mouf instance). |
||
51 | * |
||
52 | * @param MoufManager $moufManager |
||
53 | * |
||
54 | * @return MoufInstanceDescriptor |
||
55 | */ |
||
56 | public function overwriteInstanceDescriptor($name, MoufManager $moufManager) |
||
64 | |||
65 | /** |
||
66 | * Renders the object as a SQL string. |
||
67 | * |
||
68 | * @param array $parameters |
||
69 | * @param Connection $dbConnection |
||
70 | * @param int|number $indent |
||
71 | * @param int $conditionsMode |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) |
||
85 | |||
86 | /** |
||
87 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
88 | * |
||
89 | * @param VisitorInterface $visitor |
||
90 | */ |
||
91 | View Code Duplication | public function walk(VisitorInterface $visitor) |
|
109 | |||
110 | View Code Duplication | private function walkChildren(&$children, VisitorInterface $visitor) |
|
134 | } |
||
135 |
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.