Arabic   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 7
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A decide() 0 13 5
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 Arabic implements RuleInterface
12
{
13
    /**
14
     * @inheritDoc
15
     */
16
    public function decide(int $n): int
17
    {
18
        // http://www.arabeyes.org/Plural_Forms
19
        if ($n < 3) {
20
            return $n;
21
        }
22
23
        $lastTwo = $n % 100;
24
        if ($lastTwo >= 3 && $lastTwo <= 10) {
25
            return 3;
26
        }
27
28
        return $lastTwo >= 11 ? 4 : 5;
29
    }
30
}