Conditions | 15 |
Paths | 14 |
Total Lines | 20 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
23 | public static function fetchQuantifier($min = null, $max = INF, bool $lazyLoad = false) : string |
||
24 | { |
||
25 | $lazy = $lazyLoad ? '?' : ''; |
||
26 | |||
27 | switch (true) { |
||
28 | case ($min === 0 && $max === 1): |
||
29 | return '?'.$lazy; |
||
30 | case ($min === 0 && $max === INF): |
||
31 | return '*'.$lazy; |
||
32 | case ($min === 1 && $max === INF): |
||
33 | return '+'.$lazy; |
||
34 | case (is_int($min) && $min >= 1 && $max === null): |
||
35 | return '{'.$min.'}'.$lazy; |
||
36 | case (is_int($min) && (is_int($max) || $max === INF)): |
||
37 | $max = is_int($max) ? $max : ''; |
||
38 | return '{'.$min.','.$max.'}'.$lazy; |
||
39 | default: |
||
40 | return ''; |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 |