Conditions | 11 |
Paths | 11 |
Total Lines | 26 |
Code Lines | 23 |
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 |
||
40 | public function toLogLevelValue(string $level) |
||
41 | { |
||
42 | switch (strtolower($level)) { |
||
43 | case 'debug': |
||
44 | return 1; |
||
45 | case 'info': |
||
46 | return 2; |
||
47 | case 'notice': // PSR-3 |
||
48 | return 3; |
||
49 | case 'warn': |
||
50 | case 'warning': // PSR-3 |
||
51 | return 4; |
||
52 | case 'error': |
||
53 | return 5; |
||
54 | case 'critical': // PSR-3 |
||
55 | return 6; |
||
56 | case 'alert': // PSR-3 |
||
57 | return 7; |
||
58 | case 'emergency': // PSR-3 |
||
59 | return 8; |
||
60 | case 'fatal': |
||
61 | return 9; |
||
62 | default: |
||
63 | throw new LoggerException("Undefined log level: $level"); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 |