| Conditions | 10 |
| Paths | 7 |
| Total Lines | 24 |
| Code Lines | 12 |
| 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 |
||
| 22 | * |
||
| 23 | * @return DateTimeStandard|null |
||
| 24 | * |
||
| 25 | * @throws Exception if the value did not pass validation. |
||
| 26 | */ |
||
| 27 | public static function filter($value, bool $allowNull = false, DateTimeZoneStandard $timezone = null) |
||
| 28 | { |
||
| 29 | if ($value === null && $allowNull) { |
||
| 30 | return null; |
||
| 31 | } |
||
| 32 | |||
| 33 | if ($value instanceof \DateTime) { |
||
| 34 | return $value; |
||
| 35 | } |
||
| 36 | |||
| 37 | if (is_int($value) || ctype_digit($value)) { |
||
| 38 | $value = "@{$value}"; |
||
| 39 | } |
||
| 40 | |||
| 41 | if (!is_string($value) || trim($value) == '') { |
||
| 42 | throw new Exception('$value is not a non-empty string'); |
||
| 43 | } |
||
| 44 | |||
| 45 | return new \DateTime($value, $timezone); |
||
| 46 | } |
||
| 67 |