Total Complexity | 13 |
Total Lines | 89 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | final class PluralProvider implements IPlural |
||
25 | { |
||
26 | /** |
||
27 | * Default plural provider |
||
28 | */ |
||
29 | public const DEFAULT = 'enPlural'; |
||
30 | |||
31 | /** |
||
32 | * Plural provider |
||
33 | * @var string[] |
||
34 | */ |
||
35 | private $plurals = [ |
||
36 | 'cs' => 'csPlural', |
||
37 | 'en' => 'enPlural', |
||
38 | 'id' => 'zeroPlural', |
||
39 | 'ja' => 'zeroPlural', |
||
40 | 'ka' => 'zeroPlural', |
||
41 | 'ko' => 'zeroPlural', |
||
42 | 'lo' => 'zeroPlural', |
||
43 | 'ms' => 'zeroPlural', |
||
44 | 'my' => 'zeroPlural', |
||
45 | 'th' => 'zeroPlural', |
||
46 | 'vi' => 'zeroPlural', |
||
47 | 'zh' => 'zeroPlural', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * Czech plural selector (zero-one-few-other) |
||
52 | * |
||
53 | * @param int|null $n |
||
54 | * @return string |
||
55 | */ |
||
56 | public static function csPlural(?int $n): string |
||
57 | { |
||
58 | return $n === 0 |
||
59 | ? IPlural::ZERO |
||
60 | : ($n === 1 |
||
61 | ? IPlural::ONE |
||
62 | : ($n >= 2 && $n < 5 |
||
63 | ? IPlural::FEW |
||
64 | : IPlural::OTHER |
||
65 | ) |
||
66 | ); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Default plural detector (zero-one-other) |
||
71 | * |
||
72 | * @param int|null $n |
||
73 | * @return string |
||
74 | */ |
||
75 | public static function enPlural(?int $n): string |
||
76 | { |
||
77 | return $n === 0 |
||
78 | ? IPlural::ZERO |
||
79 | : ($n === 1 |
||
80 | ? IPlural::ONE |
||
81 | : IPlural::OTHER |
||
82 | ); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * No plural detector (zero-other) |
||
87 | * |
||
88 | * @param int|null $n |
||
89 | * @return string |
||
90 | */ |
||
91 | public static function zeroPlural(?int $n): string |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Get plural method |
||
100 | * |
||
101 | * @param string $locale |
||
102 | * @return callable(int|null $n): string |
||
103 | */ |
||
104 | public function getPlural(string $locale): callable |
||
115 |