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 |
||
16 | class CaseOperation implements NodeInterface |
||
17 | { |
||
18 | private $operation; |
||
19 | |||
20 | public function getOperation() |
||
24 | |||
25 | /** |
||
26 | * Sets the operation. |
||
27 | * |
||
28 | * @Important |
||
29 | * |
||
30 | * @param NodeInterface|NodeInterface[]|string $operation |
||
31 | */ |
||
32 | public function setOperation($operation) |
||
36 | |||
37 | /** |
||
38 | * Returns a Mouf instance descriptor describing this object. |
||
39 | * |
||
40 | * @param MoufManager $moufManager |
||
41 | * |
||
42 | * @return MoufInstanceDescriptor |
||
43 | */ |
||
44 | View Code Duplication | public function toInstanceDescriptor(MoufManager $moufManager) |
|
51 | |||
52 | /** |
||
53 | * Renders the object as a SQL string. |
||
54 | * |
||
55 | * @param Connection $dbConnection |
||
56 | * @param array $parameters |
||
57 | * @param number $indent |
||
58 | * @param int $conditionsMode |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) |
||
68 | |||
69 | /** |
||
70 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
71 | * |
||
72 | * @param VisitorInterface $visitor |
||
73 | */ |
||
74 | View Code Duplication | public function walk(VisitorInterface $visitor) |
|
92 | } |
||
93 |
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.