Conditions | 11 |
Paths | 15 |
Total Lines | 25 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
15 | public function __construct(array $spec, array $sortFieldsSpec) { |
||
16 | $expressions = []; |
||
17 | foreach($spec as $specReference => $dbExpr) { |
||
18 | if(is_int($specReference)) { |
||
19 | $specReference = $dbExpr; |
||
20 | } |
||
21 | $expressions[$specReference] = $dbExpr; |
||
22 | } |
||
23 | foreach($sortFieldsSpec as $sortFieldSpec) { |
||
24 | if(array_key_exists(0, $sortFieldSpec)) { |
||
25 | if(array_key_exists($sortFieldSpec[0], $expressions)) { |
||
26 | $direction = 'ASC'; |
||
27 | if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
||
28 | $direction = 'DESC'; |
||
29 | } |
||
30 | $this->fields[] = [ |
||
31 | $expressions[$sortFieldSpec[0]], |
||
32 | $direction |
||
33 | ]; |
||
34 | } |
||
35 | } else { // @phpstan-ignore-line |
||
36 | foreach($sortFieldSpec as $alias => $direction) { |
||
37 | $direction = strtoupper($direction) === 'DESC' ? 'DESC' : 'ASC'; |
||
38 | if(array_key_exists($alias, $expressions)) { |
||
39 | $this->fields[] = [$expressions[$alias], $direction]; |
||
40 | } |
||
56 |