| Total Complexity | 7 |
| Total Lines | 100 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 17 | class Pluralizer |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Uncountable word forms. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | public static $uncountable = [ |
||
| 25 | 'audio', |
||
| 26 | 'bison', |
||
| 27 | 'cattle', |
||
| 28 | 'chassis', |
||
| 29 | 'compensation', |
||
| 30 | 'coreopsis', |
||
| 31 | 'data', |
||
| 32 | 'deer', |
||
| 33 | 'education', |
||
| 34 | 'emoji', |
||
| 35 | 'equipment', |
||
| 36 | 'evidence', |
||
| 37 | 'feedback', |
||
| 38 | 'firmware', |
||
| 39 | 'fish', |
||
| 40 | 'furniture', |
||
| 41 | 'gold', |
||
| 42 | 'hardware', |
||
| 43 | 'information', |
||
| 44 | 'jedi', |
||
| 45 | 'kin', |
||
| 46 | 'knowledge', |
||
| 47 | 'love', |
||
| 48 | 'metadata', |
||
| 49 | 'money', |
||
| 50 | 'moose', |
||
| 51 | 'news', |
||
| 52 | 'nutrition', |
||
| 53 | 'offspring', |
||
| 54 | 'plankton', |
||
| 55 | 'pokemon', |
||
| 56 | 'police', |
||
| 57 | 'rain', |
||
| 58 | 'recommended', |
||
| 59 | 'related', |
||
| 60 | 'rice', |
||
| 61 | 'series', |
||
| 62 | 'sheep', |
||
| 63 | 'software', |
||
| 64 | 'species', |
||
| 65 | 'swine', |
||
| 66 | 'traffic', |
||
| 67 | 'wheat', |
||
| 68 | ]; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Get the plural form of an English word. |
||
| 72 | * |
||
| 73 | * @param string $value |
||
| 74 | * @param int $count |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | public static function plural(string $value, $count = 2) |
||
| 78 | { |
||
| 79 | if ((int) abs($count) === 1 || static::uncountable($value)) { |
||
| 80 | return $value; |
||
| 81 | } |
||
| 82 | |||
| 83 | $plural = MetadataManager::pluralize($value); |
||
| 84 | |||
| 85 | return static::matchCase($plural, $value); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Determine if the given value is uncountable. |
||
| 90 | * |
||
| 91 | * @param string $value |
||
| 92 | * @return bool |
||
| 93 | */ |
||
| 94 | protected static function uncountable($value) |
||
| 95 | { |
||
| 96 | return in_array(strtolower($value), static::$uncountable); |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Attempt to match the case on two strings. |
||
| 101 | * |
||
| 102 | * @param string $value |
||
| 103 | * @param string $comparison |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | protected static function matchCase($value, $comparison) |
||
| 117 | } |
||
| 118 | } |
||
| 119 |