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 |
||
47 | class Reserved implements NodeInterface |
||
48 | { |
||
49 | private $baseExpression; |
||
50 | |||
51 | /** |
||
52 | * Returns the base expression (the string that generated this expression). |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getBaseExpression() |
||
60 | |||
61 | /** |
||
62 | * Sets the base expression (the string that generated this expression). |
||
63 | * |
||
64 | * @param string $baseExpression |
||
65 | */ |
||
66 | public function setBaseExpression($baseExpression) |
||
70 | |||
71 | private $brackets = false; |
||
72 | |||
73 | /** |
||
74 | * Returns true if the expression is between brackets. |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function hasBrackets() |
||
82 | |||
83 | /** |
||
84 | * Sets to true if the expression is between brackets. |
||
85 | * |
||
86 | * @Important |
||
87 | * |
||
88 | * @param bool $brackets |
||
89 | */ |
||
90 | public function setBrackets($brackets) |
||
94 | |||
95 | /** |
||
96 | * Returns a Mouf instance descriptor describing this object. |
||
97 | * |
||
98 | * @param MoufManager $moufManager |
||
99 | * |
||
100 | * @return MoufInstanceDescriptor |
||
101 | */ |
||
102 | public function toInstanceDescriptor(MoufManager $moufManager) |
||
110 | |||
111 | /** |
||
112 | * Renders the object as a SQL string. |
||
113 | * |
||
114 | * @param array $parameters |
||
115 | * @param Connection $dbConnection |
||
116 | * @param int|number $indent |
||
117 | * @param int $conditionsMode |
||
118 | * @return string |
||
119 | */ |
||
120 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) |
||
134 | |||
135 | /** |
||
136 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
137 | * |
||
138 | * @param VisitorInterface $visitor |
||
139 | */ |
||
140 | View Code Duplication | public function walk(VisitorInterface $visitor) { |
|
148 | } |
||
149 |
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.