Russian::decide()   B
last analyzed

Complexity

Conditions 7
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
rs 8.8333
c 0
b 0
f 0
cc 7
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Polyglot\Pluralization\Rules;
6
7
/**
8
 * @package Polyglot/Pluralization/Rules
9
 * @author  Mihai MATEI <[email protected]>
10
 */
11
class Russian implements RuleInterface
12
{
13
    /**
14
     * @inheritDoc
15
     */
16
    public function decide(int $n): int
17
    {
18
        $lastTwo = $n % 100;
19
        $end = $lastTwo % 10;
20
21
        if ($lastTwo !== 11 && $end === 1) {
22
            return 0;
23
        }
24
        if (2 <= $end && $end <= 4 && !($lastTwo >= 12 && $lastTwo <= 14)) {
25
            return 1;
26
        }
27
        return 2;
28
    }
29
}