Conditions | 13 |
Paths | 13 |
Total Lines | 19 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 13.0501 |
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 |
||
153 | 22 | final public static function fromNumber(int $number): self |
|
154 | { |
||
155 | switch ($number) { |
||
156 | 22 | case 1: |
|
157 | 20 | case 2: |
|
158 | 17 | case 3: |
|
159 | 12 | case 4: |
|
160 | 9 | case 5: |
|
161 | 8 | case 6: |
|
162 | 7 | case 7: |
|
163 | 5 | case 8: |
|
164 | 4 | case 9: |
|
165 | 3 | case 10: |
|
166 | 2 | case 11: |
|
167 | 1 | case 12: |
|
168 | 22 | return new self($number); |
|
169 | } |
||
170 | |||
171 | throw new \InvalidArgumentException(sprintf('Given number %d is an invalid Month number', $number)); |
||
172 | } |
||
174 |