| Conditions | 18 |
| Paths | 18 |
| Total Lines | 31 |
| 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 |
||
| 50 | public static function from_error(string $severity) : string |
||
| 51 | { |
||
| 52 | $severity = strtolower($severity); |
||
| 53 | |||
| 54 | switch ($severity) { |
||
| 55 | case 'deprecated': |
||
| 56 | case 'user_deprecated': |
||
| 57 | case 'warning': |
||
| 58 | case 'user_warning': |
||
| 59 | return Severity::WARNING; |
||
| 60 | case 'error': |
||
| 61 | case 'parse': |
||
| 62 | case 'coreerror': |
||
| 63 | case 'corwarning': // Possibly misspelling |
||
| 64 | case 'corewarning': |
||
| 65 | case 'compilerrror': // Possibly misspelling |
||
| 66 | case 'compilerror': |
||
| 67 | case 'compilewarning': |
||
| 68 | return Severity::FATAL; |
||
| 69 | case 'recoverablerror': |
||
| 70 | case 'user_error': |
||
| 71 | return Severity::ERROR; |
||
| 72 | case 'notice': |
||
| 73 | case 'user_notice': |
||
| 74 | case 'strict': |
||
| 75 | return Severity::INFO; |
||
| 76 | default: |
||
| 77 | // It's an error until proven otherwise |
||
| 78 | return Severity::ERROR; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 83 |