TimeSpeller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A spellUnit() 0 14 5
1
<?php
2
namespace morphos\Russian;
3
4
use InvalidArgumentException;
5
6
class TimeSpeller extends \morphos\TimeSpeller
7
{
8
    /**
9
     * @var string[]
10
     */
11
    protected static $units = [
12
        self::YEAR => 'год',
13
        self::MONTH => 'месяц',
14
        self::DAY => 'день',
15
        self::HOUR => 'час',
16
        self::MINUTE => 'минута',
17
        self::SECOND => 'секунда',
18
    ];
19
20
    const AGO = 'назад';
21
    const IN = 'через';
22
23
    const AND_WORD = 'и';
24
25
    const JUST_NOW = 'только что';
26
27
    /**
28
     * @param int $count
29
     * @param string $unit
30
     *
31
     * @return string
32
     * @throws \Exception
33
     */
34 19
    public static function spellUnit($count, $unit)
35
    {
36 19
        if (!isset(static::$units[$unit])) {
37 1
            throw new InvalidArgumentException('Unknown time unit: '.$unit);
38
        }
39
40 18
        if ($count === 1 && in_array($unit, [self::SECOND, self::MINUTE], true)) {
41 1
            if ($unit === self::SECOND)
42 1
                return '1 секунду';
43 1
            return '1 минуту';
44
        }
45
46 17
        return pluralize($count, static::$units[$unit]);
47
    }
48
}
49