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