| Conditions | 10 |
| Paths | 28 |
| Total Lines | 42 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 10.1728 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 27 | 16 | public static function spellInterval(DateInterval $interval, $options = 0, $limit = 0) |
|
| 28 | { |
||
| 29 | 16 | $parts = []; |
|
| 30 | 16 | $k = 0; |
|
| 31 | foreach ([ |
||
| 32 | 16 | 'y' => self::YEAR, |
|
| 33 | 16 | 'm' => self::MONTH, |
|
| 34 | 16 | 'd' => self::DAY, |
|
| 35 | 16 | 'h' => self::HOUR, |
|
| 36 | 16 | 'i' => self::MINUTE, |
|
| 37 | 16 | 's' => self::SECOND |
|
| 38 | ] as $interval_field => $unit) { |
||
| 39 | 16 | if ($interval->{$interval_field} > 0) { |
|
| 40 | 16 | if($limit > 0 && $k >= $limit) { |
|
| 41 | break; |
||
| 42 | } |
||
| 43 | 16 | $parts[] = static::spellUnit($interval->{$interval_field}, $unit); |
|
|
|
|||
| 44 | 16 | $k++; |
|
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | 16 | if (empty($parts)) { |
|
| 49 | return static::JUST_NOW; |
||
| 50 | } |
||
| 51 | |||
| 52 | 16 | if ($options & self::SEPARATE && count($parts) > 1) { |
|
| 53 | 6 | $last_part = array_pop($parts); |
|
| 54 | 6 | $spelled = implode(', ', $parts).' '.static::AND_WORD.' '.$last_part; |
|
| 55 | } else { |
||
| 56 | 10 | $spelled = implode(' ', $parts); |
|
| 57 | } |
||
| 58 | |||
| 59 | 16 | if ($options & self::DIRECTION) { |
|
| 60 | 4 | if ($interval->invert) { |
|
| 61 | $spelled = static::IN.' '.$spelled; |
||
| 62 | } else { |
||
| 63 | 4 | $spelled .= ' '.static::AGO; |
|
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | 16 | return $spelled; |
|
| 68 | } |
||
| 69 | } |
||
| 70 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.