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 | final class QueryBuilder implements QueryBuilderInterface |
||
|
|||
20 | { |
||
21 | /** |
||
22 | * @var ObjectNode |
||
23 | */ |
||
24 | private $rootNode; |
||
25 | |||
26 | /** |
||
27 | * @var AbstractNode |
||
28 | */ |
||
29 | private $node; |
||
30 | |||
31 | 19 | public function __construct() |
|
38 | |||
39 | /** |
||
40 | * @param array ...$arguments |
||
41 | * |
||
42 | * @return QueryBuilderInterface |
||
43 | * |
||
44 | * @throws \Exception |
||
45 | */ |
||
46 | 16 | public function add(...$arguments): QueryBuilderInterface |
|
54 | |||
55 | /** |
||
56 | * @param AbstractNode $node |
||
57 | * |
||
58 | * @return QueryBuilderInterface |
||
59 | * |
||
60 | * @throws \Exception |
||
61 | */ |
||
62 | 5 | View Code Duplication | public function addToArrayNode(AbstractNode $node): QueryBuilderInterface |
73 | |||
74 | /** |
||
75 | * @param string $key |
||
76 | * @param AbstractNode $node |
||
77 | * |
||
78 | * @return QueryBuilderInterface |
||
79 | * |
||
80 | * @throws \Exception |
||
81 | */ |
||
82 | 17 | View Code Duplication | public function addToObjectNode(string $key, AbstractNode $node): QueryBuilderInterface |
93 | |||
94 | /** |
||
95 | * @param AbstractNode $node |
||
96 | */ |
||
97 | 17 | private function reassignParent(AbstractNode $node) |
|
103 | |||
104 | /** |
||
105 | * @return QueryBuilderInterface |
||
106 | * |
||
107 | * @throws \Exception |
||
108 | */ |
||
109 | 2 | public function end(): QueryBuilderInterface |
|
117 | |||
118 | /** |
||
119 | * @param bool $allowSerializeEmpty |
||
120 | * |
||
121 | * @return ArrayNode |
||
122 | */ |
||
123 | 5 | public function arrayNode(bool $allowSerializeEmpty = false): ArrayNode |
|
127 | |||
128 | /** |
||
129 | * @param bool|null $value |
||
130 | * @param bool $allowSerializeEmpty |
||
131 | * |
||
132 | * @return BoolNode |
||
133 | */ |
||
134 | 1 | public function boolNode($value = null, bool $allowSerializeEmpty = false): BoolNode |
|
138 | |||
139 | /** |
||
140 | * @param float|null $value |
||
141 | * @param bool $allowSerializeEmpty |
||
142 | * |
||
143 | * @return FloatNode |
||
144 | */ |
||
145 | 1 | public function floatNode($value = null, bool $allowSerializeEmpty = false): FloatNode |
|
149 | |||
150 | /** |
||
151 | * @param int|null $value |
||
152 | * @param bool $allowSerializeEmpty |
||
153 | * |
||
154 | * @return IntNode |
||
155 | */ |
||
156 | 4 | public function intNode($value = null, bool $allowSerializeEmpty = false): IntNode |
|
160 | |||
161 | /** |
||
162 | * @return NullNode |
||
163 | */ |
||
164 | 1 | public function nullNode(): NullNode |
|
168 | |||
169 | /** |
||
170 | * @param bool $allowSerializeEmpty |
||
171 | * |
||
172 | * @return ObjectNode |
||
173 | */ |
||
174 | 16 | public function objectNode(bool $allowSerializeEmpty = false): ObjectNode |
|
178 | |||
179 | /** |
||
180 | * @param string|null $value |
||
181 | * @param bool $allowSerializeEmpty |
||
182 | * |
||
183 | * @return StringNode |
||
184 | */ |
||
185 | 13 | public function stringNode($value = null, bool $allowSerializeEmpty = false): StringNode |
|
189 | |||
190 | /** |
||
191 | * @return \stdClass|null |
||
192 | */ |
||
193 | 16 | public function serialize() |
|
197 | |||
198 | /** |
||
199 | * @param bool $beautify |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | 16 | View Code Duplication | public function json(bool $beautify = false): string |
215 | } |
||
216 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.