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 |
||
46 | class LimitNode implements NodeInterface |
||
47 | { |
||
48 | private $value; |
||
49 | |||
50 | public function getValue() |
||
54 | |||
55 | /** |
||
56 | * Sets the value. |
||
57 | * |
||
58 | * @Important |
||
59 | * |
||
60 | * @param string $value |
||
61 | */ |
||
62 | public function setValue($value) |
||
66 | |||
67 | /** |
||
68 | * Returns a Mouf instance descriptor describing this object. |
||
69 | * |
||
70 | * @param MoufManager $moufManager |
||
71 | * |
||
72 | * @return MoufInstanceDescriptor |
||
73 | */ |
||
74 | View Code Duplication | public function toInstanceDescriptor(MoufManager $moufManager) |
|
81 | |||
82 | /** |
||
83 | * Renders the object as a SQL string. |
||
84 | * |
||
85 | * @param array $parameters |
||
86 | * @param Connection $dbConnection |
||
87 | * @param int|number $indent |
||
88 | * @param int $conditionsMode |
||
89 | * @return string |
||
90 | * @throws \Exception |
||
91 | */ |
||
92 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) |
||
106 | |||
107 | /** |
||
108 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
109 | * |
||
110 | * @param VisitorInterface $visitor |
||
111 | * @return NodeInterface|null|string Can return null if nothing is to be done or a node that should replace this node, or NodeTraverser::REMOVE_NODE to remove the node |
||
112 | */ |
||
113 | View Code Duplication | public function walk(VisitorInterface $visitor) { |
|
121 | } |
||
122 |
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.