TimeSpeller::spellUnit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace morphos\English;
3
4
use InvalidArgumentException;
5
6
class TimeSpeller extends \morphos\TimeSpeller
7
{
8
    /**
9
     * @var string[]
10
     * @phpstan-var array<string, string>
11
     */
12
    protected static $units = [
13
        self::YEAR => 'year',
14
        self::MONTH => 'month',
15
        self::DAY => 'day',
16
        self::HOUR => 'hour',
17
        self::MINUTE => 'minute',
18
        self::SECOND => 'second',
19
    ];
20
21
    /**
22
     * @param int $count
23
     * @param string $unit
24
     * @return string
25
     */
26 17
    public static function spellUnit($count, $unit)
27
    {
28 17
        if (!isset(static::$units[$unit])) {
29 1
            throw new InvalidArgumentException('Unknown time unit: '.$unit);
30
        }
31
32 16
        return $count.' '.NounPluralization::pluralize(static::$units[$unit], $count);
33
    }
34
}
35