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