These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Nip\Inflector\Traits; |
||
4 | |||
5 | /** |
||
6 | * Trait InflectionPluralizeTrait |
||
7 | * @package Nip\Inflector\Traits |
||
8 | * |
||
9 | * @method pluralize($string) |
||
10 | */ |
||
11 | trait InflectionPluralizeTrait |
||
12 | { |
||
13 | |||
14 | protected $plural = [ |
||
15 | '/(s)tatus$/i' => '\1tatuses', |
||
16 | '/(quiz)$/i' => '\1zes', |
||
17 | '/^(ox)$/i' => '\1\2en', |
||
18 | '/([m|l])ouse$/i' => '\1ice', |
||
19 | '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', |
||
20 | '/(x|ch|ss|sh)$/i' => '\1es', |
||
21 | '/([^aeiouy]|qu)y$/i' => '\1ies', |
||
22 | '/(hive)$/i' => '\1s', |
||
23 | '/(chef)$/i' => '\1s', |
||
24 | '/(?:([^f])fe|([lre])f)$/i' => '\1\2ves', |
||
25 | '/sis$/i' => 'ses', |
||
26 | '/([ti])um$/i' => '\1a', |
||
27 | '/(p)erson$/i' => '\1eople', |
||
28 | '/(?<!u)(m)an$/i' => '\1en', |
||
29 | '/(c)hild$/i' => '\1hildren', |
||
30 | '/(buffal|tomat)o$/i' => '\1\2oes', |
||
31 | '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin)us$/i' => '\1i', |
||
32 | '/us$/i' => 'uses', |
||
33 | '/(alias)$/i' => '\1es', |
||
34 | '/(ax|cris|test)is$/i' => '\1es', |
||
35 | '/s$/' => 's', |
||
36 | '/^$/' => '', |
||
37 | '/$/' => 's', |
||
38 | ]; |
||
39 | |||
40 | protected $uncountable = [ |
||
41 | '.*[nrlm]ese', |
||
42 | '.*data', |
||
43 | '.*deer', |
||
44 | '.*fish', |
||
45 | '.*measles', |
||
46 | '.*ois', |
||
47 | '.*pox', |
||
48 | '.*sheep', |
||
49 | 'people', |
||
50 | 'feedback', |
||
51 | 'stadia', |
||
52 | '.*?media', |
||
53 | 'chassis', |
||
54 | 'clippers', |
||
55 | 'debris', |
||
56 | 'diabetes', |
||
57 | 'equipment', |
||
58 | 'gallows', |
||
59 | 'graffiti', |
||
60 | 'headquarters', |
||
61 | 'information', |
||
62 | 'innings', |
||
63 | 'news', |
||
64 | 'nexus', |
||
65 | 'pokemon', |
||
66 | 'proceedings', |
||
67 | 'research', |
||
68 | 'sea[- ]bass', |
||
69 | 'series', |
||
70 | 'species', |
||
71 | 'weather' |
||
72 | ]; |
||
73 | |||
74 | protected $irregular = [ |
||
75 | 'atlas' => 'atlases', |
||
76 | 'beef' => 'beefs', |
||
77 | 'brief' => 'briefs', |
||
78 | 'brother' => 'brothers', |
||
79 | 'cafe' => 'cafes', |
||
80 | 'child' => 'children', |
||
81 | 'cookie' => 'cookies', |
||
82 | 'corpus' => 'corpuses', |
||
83 | 'cow' => 'cows', |
||
84 | 'criterion' => 'criteria', |
||
85 | 'ganglion' => 'ganglions', |
||
86 | 'genie' => 'genies', |
||
87 | 'genus' => 'genera', |
||
88 | 'graffito' => 'graffiti', |
||
89 | 'hoof' => 'hoofs', |
||
90 | 'loaf' => 'loaves', |
||
91 | 'man' => 'men', |
||
92 | 'money' => 'monies', |
||
93 | 'mongoose' => 'mongooses', |
||
94 | 'move' => 'moves', |
||
95 | 'mythos' => 'mythoi', |
||
96 | 'niche' => 'niches', |
||
97 | 'numen' => 'numina', |
||
98 | 'occiput' => 'occiputs', |
||
99 | 'octopus' => 'octopuses', |
||
100 | 'opus' => 'opuses', |
||
101 | 'ox' => 'oxen', |
||
102 | 'penis' => 'penises', |
||
103 | 'person' => 'people', |
||
104 | 'sex' => 'sexes', |
||
105 | 'soliloquy' => 'soliloquies', |
||
106 | 'testis' => 'testes', |
||
107 | 'trilby' => 'trilbys', |
||
108 | 'turf' => 'turfs', |
||
109 | 'potato' => 'potatoes', |
||
110 | 'hero' => 'heroes', |
||
111 | 'tooth' => 'teeth', |
||
112 | 'goose' => 'geese', |
||
113 | 'foot' => 'feet', |
||
114 | 'foe' => 'foes', |
||
115 | 'sieve' => 'sieves' |
||
116 | ]; |
||
117 | |||
118 | /** |
||
119 | * @param $word |
||
120 | * @return bool|mixed |
||
121 | */ |
||
122 | 1 | protected function doPluralize($word) |
|
123 | { |
||
124 | 1 | $lowerCased_word = strtolower($word); |
|
125 | |||
126 | 1 | foreach ($this->uncountable as $_uncountable) { |
|
127 | 1 | if (substr($lowerCased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
128 | 1 | return $word; |
|
129 | } |
||
130 | } |
||
131 | |||
132 | 1 | View Code Duplication | foreach ($this->irregular as $_plural => $_singular) { |
0 ignored issues
–
show
|
|||
133 | 1 | if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
134 | 1 | return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
135 | } |
||
136 | } |
||
137 | |||
138 | 1 | foreach ($this->plural as $rule => $replacement) { |
|
139 | 1 | if (preg_match($rule, $word)) { |
|
140 | 1 | return preg_replace($rule, $replacement, $word); |
|
141 | } |
||
142 | } |
||
143 | |||
144 | return false; |
||
145 | } |
||
146 | } |
||
147 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.