These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace morphos\English; |
||
3 | |||
4 | use InvalidArgumentException; |
||
5 | |||
6 | class TimeSpeller extends \morphos\TimeSpeller |
||
7 | { |
||
8 | protected static $units = [ |
||
9 | self::YEAR => 'year', |
||
10 | self::MONTH => 'month', |
||
11 | self::DAY => 'day', |
||
12 | self::HOUR => 'hour', |
||
13 | self::MINUTE => 'minute', |
||
14 | self::SECOND => 'second', |
||
15 | ]; |
||
16 | |||
17 | /** |
||
18 | * @param $count |
||
19 | * @param $unit |
||
20 | * @return string |
||
21 | */ |
||
22 | 14 | View Code Duplication | public static function spellUnit($count, $unit) |
0 ignored issues
–
show
|
|||
23 | { |
||
24 | 14 | if (!isset(self::$units[$unit])) { |
|
25 | 1 | throw new InvalidArgumentException('Unknown time unit: '.$unit); |
|
26 | } |
||
27 | |||
28 | 13 | return $count.' '.NounPluralization::pluralize(self::$units[$unit], $count); |
|
29 | } |
||
30 | } |
||
31 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.