| Conditions | 13 |
| Paths | 13 |
| Total Lines | 61 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 43 |
| CRAP Score | 13 |
| 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 |
||
| 30 | 29 | public function get(DateTime $datetime, $name) |
|
| 31 | { |
||
| 32 | 29 | $value = null; |
|
| 33 | |||
| 34 | switch ($name) |
||
| 35 | { |
||
| 36 | 29 | case 'daysinmonth': |
|
| 37 | 2 | $value = $datetime->format('t'); |
|
| 38 | 2 | break; |
|
| 39 | |||
| 40 | 27 | case 'dayofweek': |
|
| 41 | 2 | $value = $datetime->format('N'); |
|
| 42 | 2 | break; |
|
| 43 | |||
| 44 | 25 | case 'dayofyear': |
|
| 45 | 2 | $value = $datetime->format('z'); |
|
| 46 | 2 | break; |
|
| 47 | |||
| 48 | 23 | case 'isleapyear': |
|
| 49 | 4 | $value = (boolean) $datetime->format('L'); |
|
| 50 | 4 | break; |
|
| 51 | |||
| 52 | 19 | case 'day': |
|
| 53 | 2 | $value = $datetime->format('d'); |
|
| 54 | 2 | break; |
|
| 55 | |||
| 56 | 17 | case 'hour': |
|
| 57 | 2 | $value = $datetime->format('H'); |
|
| 58 | 2 | break; |
|
| 59 | |||
| 60 | 15 | case 'minute': |
|
| 61 | 2 | $value = $datetime->format('i'); |
|
| 62 | 2 | break; |
|
| 63 | |||
| 64 | 13 | case 'second': |
|
| 65 | 2 | $value = $datetime->format('s'); |
|
| 66 | 2 | break; |
|
| 67 | |||
| 68 | 11 | case 'month': |
|
| 69 | 2 | $value = $datetime->format('m'); |
|
| 70 | 2 | break; |
|
| 71 | |||
| 72 | 9 | case 'ordinal': |
|
| 73 | 4 | $value = $datetime->format('S'); |
|
| 74 | 4 | break; |
|
| 75 | |||
| 76 | 5 | case 'week': |
|
| 77 | 2 | $value = $datetime->format('W'); |
|
| 78 | 2 | break; |
|
| 79 | |||
| 80 | 3 | case 'year': |
|
| 81 | 2 | $value = $datetime->format('Y'); |
|
| 82 | 2 | break; |
|
| 83 | |||
| 84 | 1 | default: |
|
| 85 | 1 | $trace = debug_backtrace(); |
|
| 86 | 1 | trigger_error('Undefined property: ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); |
|
| 87 | 1 | } |
|
| 88 | |||
| 89 | 28 | return $value; |
|
| 90 | } |
||
| 91 | } |
||
| 92 |