| Conditions | 10 |
| Paths | 512 |
| Total Lines | 20 |
| 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 |
||
| 34 | public static function diffAsText($datetime1, $datetime2, $absolute = false) |
||
| 35 | { |
||
| 36 | if (!($datetime1 instanceof \DateTimeInterface)) { |
||
| 37 | $datetime1 = new static($datetime1); |
||
| 38 | } |
||
| 39 | if (!($datetime2 instanceof \DateTimeInterface)) { |
||
| 40 | $datetime2 = new static($datetime2); |
||
| 41 | } |
||
| 42 | |||
| 43 | $interval = $datetime1->diff($datetime2, $absolute); |
||
| 44 | $str = ''; |
||
| 45 | $str .= $interval->y ? $interval->y . ' year. ' : ''; |
||
| 46 | $str .= $interval->m ? $interval->m . ' mon. ' : ''; |
||
| 47 | $str .= $interval->d ? $interval->d . ' day. ' : ''; |
||
| 48 | $str .= $interval->h ? $interval->h . ' hour. ' : ''; |
||
| 49 | $str .= $interval->i ? $interval->i . ' min. ' : ''; |
||
| 50 | $str .= $interval->s || $str === '' ? $interval->s . ' sec. ' : ''; |
||
| 51 | |||
| 52 | return rtrim($str); |
||
| 53 | } |
||
| 54 | } |
||
| 55 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.