| Conditions | 10 |
| Paths | 8 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 18 |
| Ratio | 58.06 % |
| 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 |
||
| 82 | protected function _normalize($date) |
||
| 83 | { |
||
| 84 | $date = preg_replace('/[^0-9\-]/', '', $date); |
||
| 85 | $parts = explode('-', $date); |
||
| 86 | $year = date('Y'); |
||
| 87 | $month = 1; |
||
| 88 | $day = 1; |
||
| 89 | |||
| 90 | View Code Duplication | if (!empty($parts[0]) && |
|
| 91 | 1 <= intval($parts[0]) && |
||
| 92 | intval($parts[0]) <= 32767 |
||
| 93 | ) { |
||
| 94 | $year = intval($parts[0]); |
||
| 95 | } |
||
| 96 | |||
| 97 | View Code Duplication | if (!empty($parts[1]) && |
|
| 98 | 1 <= intval($parts[1]) && |
||
| 99 | intval($parts[1]) <= 12 |
||
| 100 | ) { |
||
| 101 | $month = intval($parts[1]); |
||
| 102 | } |
||
| 103 | |||
| 104 | View Code Duplication | if (!empty($parts[2]) && |
|
| 105 | 1 <= intval($parts[2]) && |
||
| 106 | intval($parts[2]) <= 31 |
||
| 107 | ) { |
||
| 108 | $day = intval($parts[2]); |
||
| 109 | } |
||
| 110 | |||
| 111 | return date('Y-m-d', strtotime("{$year}-{$month}-{$day}")); |
||
| 112 | } |
||
| 113 | } |
||
| 114 |