Complex classes like ExprBuilder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ExprBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class ExprBuilder implements ExpressionInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var ExpressionInterface $wrappedExpression |
||
26 | */ |
||
27 | private $wrappedExpression; |
||
28 | |||
29 | /** |
||
30 | * ExprBuilder constructor. |
||
31 | */ |
||
32 | 25 | public function __construct() |
|
36 | /** |
||
37 | * @param mixed $expression |
||
38 | * |
||
39 | * @return ExpressionInterface |
||
40 | */ |
||
41 | 31 | public static function normalizeExpression($expression) |
|
71 | |||
72 | /** |
||
73 | * @return ExpressionInterface |
||
74 | */ |
||
75 | 1 | public function getWrappedExpression() |
|
79 | |||
80 | /** |
||
81 | * @inheritdoc |
||
82 | */ |
||
83 | 25 | public function compile() |
|
87 | |||
88 | /** |
||
89 | * @param mixed $alias |
||
90 | * |
||
91 | * @return ExprBuilder |
||
92 | */ |
||
93 | 3 | public function alias($alias) |
|
99 | |||
100 | /** |
||
101 | * @return ExprBuilder |
||
102 | */ |
||
103 | public function sumNullable() |
||
107 | |||
108 | /** |
||
109 | * @return ExprBuilder |
||
110 | */ |
||
111 | 1 | public function in() |
|
117 | |||
118 | /** |
||
119 | * @return ExprBuilder |
||
120 | */ |
||
121 | 1 | public function using() |
|
125 | |||
126 | /** |
||
127 | * @return ExprBuilder |
||
128 | */ |
||
129 | 1 | public function desc() |
|
133 | |||
134 | /** |
||
135 | * @return ExprBuilder |
||
136 | */ |
||
137 | 1 | public function asc() |
|
141 | |||
142 | /** |
||
143 | * @param string $connector |
||
144 | * @param mixed $expression |
||
145 | * |
||
146 | * @return ExprBuilder |
||
147 | */ |
||
148 | 1 | public function conjunction($connector, $expression) |
|
154 | |||
155 | ############################### |
||
156 | ### COMPARISION EXPRESSIONS ### |
||
157 | ############################### |
||
158 | |||
159 | /** |
||
160 | * @param mixed $from |
||
161 | * @param mixed $to |
||
162 | * |
||
163 | * @return ExprBuilder |
||
164 | */ |
||
165 | 1 | public function between($from, $to) |
|
172 | |||
173 | /** |
||
174 | * @param mixed $expression |
||
175 | * |
||
176 | * @return ExprBuilder |
||
177 | */ |
||
178 | public function eq($expression) |
||
184 | |||
185 | /** |
||
186 | * @param mixed $expression |
||
187 | * |
||
188 | * @return ExprBuilder |
||
189 | */ |
||
190 | 1 | public function gt($expression) |
|
196 | |||
197 | /** |
||
198 | * @param mixed $expression |
||
199 | * |
||
200 | * @return ExprBuilder |
||
201 | */ |
||
202 | public function gte($expression) |
||
208 | |||
209 | /** |
||
210 | * @return ExprBuilder |
||
211 | */ |
||
212 | public function isNull() |
||
216 | |||
217 | /** |
||
218 | * @param mixed $expression |
||
219 | * |
||
220 | * @return ExprBuilder |
||
221 | */ |
||
222 | public function lt($expression) |
||
228 | |||
229 | /** |
||
230 | * @param mixed $expression |
||
231 | * |
||
232 | * @return ExprBuilder |
||
233 | */ |
||
234 | public function lte($expression) |
||
240 | |||
241 | /** |
||
242 | * @param mixed $expression |
||
243 | * |
||
244 | * @return ExprBuilder |
||
245 | */ |
||
246 | public function neq($expression) |
||
252 | |||
253 | /** |
||
254 | * @param mixed $from |
||
255 | * @param mixed $to |
||
256 | * |
||
257 | * @return ExprBuilder |
||
258 | */ |
||
259 | 1 | public function notBetween($from, $to) |
|
266 | |||
267 | /** |
||
268 | * @param mixed $expression |
||
269 | * |
||
270 | * @return ExprBuilder |
||
271 | */ |
||
272 | public function nullEq($expression) |
||
278 | |||
279 | ############################## |
||
280 | ### ARITHMETIC EXPRESSIONS ### |
||
281 | ############################## |
||
282 | |||
283 | /** |
||
284 | * @param mixed $right |
||
285 | * |
||
286 | * @return ExprBuilder |
||
287 | */ |
||
288 | 1 | public function add($right) |
|
294 | |||
295 | /** |
||
296 | * @param mixed $right |
||
297 | * |
||
298 | * @return ExprBuilder |
||
299 | */ |
||
300 | public function div($right) |
||
306 | |||
307 | /** |
||
308 | * @param mixed $right |
||
309 | * |
||
310 | * @return ExprBuilder |
||
311 | */ |
||
312 | public function divide($right) |
||
318 | |||
319 | /** |
||
320 | * @param mixed $right |
||
321 | * |
||
322 | * @return ExprBuilder |
||
323 | */ |
||
324 | public function modulo($right) |
||
330 | |||
331 | /** |
||
332 | * @param mixed $right |
||
333 | * |
||
334 | * @return ExprBuilder |
||
335 | */ |
||
336 | public function multiply($right) |
||
342 | |||
343 | /** |
||
344 | * @param mixed $right |
||
345 | * |
||
346 | * @return ExprBuilder |
||
347 | */ |
||
348 | public function subtract($right) |
||
354 | |||
355 | ################# |
||
356 | ### FUNCTIONS ### |
||
357 | ################# |
||
358 | |||
359 | /** |
||
360 | * @return ExprBuilder |
||
361 | */ |
||
362 | public function asci() |
||
366 | |||
367 | /** |
||
368 | * @return ExprBuilder |
||
369 | */ |
||
370 | public function bin() |
||
374 | |||
375 | /** |
||
376 | * @return ExprBuilder |
||
377 | */ |
||
378 | public function bitLength() |
||
382 | |||
383 | /** |
||
384 | * @return ExprBuilder |
||
385 | */ |
||
386 | 1 | public function char() |
|
390 | |||
391 | /** |
||
392 | * @return ExprBuilder |
||
393 | */ |
||
394 | 1 | public function coalesce() |
|
398 | |||
399 | /** |
||
400 | * @return ExprBuilder |
||
401 | */ |
||
402 | public function concat() |
||
406 | |||
407 | /** |
||
408 | * @return ExprBuilder |
||
409 | */ |
||
410 | public function concatWs() |
||
414 | |||
415 | /** |
||
416 | * @return ExprBuilder |
||
417 | */ |
||
418 | public function elt() |
||
422 | |||
423 | /** |
||
424 | * @return ExprBuilder |
||
425 | */ |
||
426 | public function exportSet() |
||
430 | |||
431 | /** |
||
432 | * @return ExprBuilder |
||
433 | */ |
||
434 | public function field() |
||
438 | |||
439 | /** |
||
440 | * @param mixed $expression |
||
441 | * |
||
442 | * @return ExprBuilder |
||
443 | */ |
||
444 | 1 | public function ifNull($expression) |
|
450 | |||
451 | /** |
||
452 | * @return ExprBuilder |
||
453 | */ |
||
454 | 2 | public function max() |
|
458 | |||
459 | /** |
||
460 | * @return ExprBuilder |
||
461 | */ |
||
462 | 4 | public function sum() |
|
466 | |||
467 | /** |
||
468 | * @return ExprBuilder |
||
469 | */ |
||
470 | 1 | public function year() |
|
474 | } |