Passed
Push — main ( 502e97...5fe35e )
by Alex
01:17
created

TraitPluralize::ruleUncountable()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 107
Code Lines 105

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 105
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 107
rs 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Erykai\Pluralize;
4
5
/**
6
 * Trait Pluralize
7
 */
8
trait TraitPluralize
9
{
10
    /**
11
     * @param string $string
12
     * @return bool
13
     */
14
    protected function uncountable(string $string): bool
15
    {
16
        if (in_array(strtolower($string), $this->getUncountable(), true)) {
0 ignored issues
show
Bug introduced by
It seems like getUncountable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        if (in_array(strtolower($string), $this->/** @scrutinizer ignore-call */ getUncountable(), true)) {
Loading history...
17
            return true;
18
        }
19
        return false;
20
    }
21
22
    /**
23
     * @return string[]
24
     */
25
    protected function ruleIrregular(): array
26
    {
27
        return [
28
            'move' => 'moves',
29
            'sex' => 'sexes',
30
            'child' => 'children',
31
            'man' => 'men',
32
            'person' => 'people',
33
            'I' => 'we',
34
            'me' => 'us',
35
            'he' => 'they',
36
            'she' => 'they',
37
            'them' => 'them',
38
            'myself' => 'ourselves',
39
            'yourself' => 'yourselves',
40
            'itself' => 'themselves',
41
            'herself' => 'themselves',
42
            'himself' => 'themselves',
43
            'themself' => 'themselves',
44
            'is' => 'are',
45
            'was' => 'were',
46
            'has' => 'have',
47
            'this' => 'these',
48
            'that' => 'those',
49
            'echo' => 'echoes',
50
            'dingo' => 'dingoes',
51
            'volcano' => 'volcanoes',
52
            'tornado' => 'tornadoes',
53
            'torpedo' => 'torpedoes',
54
            'genus' => 'genera',
55
            'viscus' => 'viscera',
56
            'stigma' => 'stigmata',
57
            'stoma' => 'stomata',
58
            'dogma' => 'dogmata',
59
            'lemma' => 'lemmata',
60
            'schema' => 'schemata',
61
            'anathema' => 'anathemata',
62
            'ox' => 'oxen',
63
            'axe' => 'axes',
64
            'die' => 'dice',
65
            'yes' => 'yeses',
66
            'foot' => 'feet',
67
            'eave' => 'eaves',
68
            'goose' => 'geese',
69
            'tooth' => 'teeth',
70
            'quiz' => 'quizzes',
71
            'human' => 'humans',
72
            'proof' => 'proofs',
73
            'carve' => 'carves',
74
            'valve' => 'valves',
75
            'looey' => 'looies',
76
            'thief' => 'thieves',
77
            'groove' => 'grooves',
78
            'pickaxe' => 'pickaxes',
79
            'passerby' => 'passersby',
80
            'cookie' => 'cookies'
81
        ];
82
    }
83
84
    /**
85
     * @return string[]
86
     */
87
    protected function rulePlural(): array
88
    {
89
        return [
90
            '/(quiz)$/i' => "$1zes",
91
            '/^(ox)$/i' => "$1en",
92
            '/([m|l])ouse$/i' => "$1ice",
93
            '/(matr|vert|ind)ix|ex$/i' => "$1ices",
94
            '/(x|ch|ss|sh)$/i' => "$1es",
95
            '/([^aeiouy]|qu)y$/i' => "$1ies",
96
            '/(hive)$/i' => "$1s",
97
            '/(?:([^f])fe|([lr])f)$/i' => "$1$2ves",
98
            '/(shea|lea|loa|thie)f$/i' => "$1ves",
99
            '/sis$/i' => "ses",
100
            '/([ti])um$/i' => "$1a",
101
            '/(tomat|potat|ech|her|vet)o$/i' => "$1oes",
102
            '/(bu)s$/i' => "$1ses",
103
            '/(alias)$/i' => "$1es",
104
            '/(octop)us$/i' => "$1i",
105
            '/(ax|test)is$/i' => "$1es",
106
            '/(us)$/i' => "$1es",
107
            '/s$/i' => "s",
108
            '/$/' => "s"
109
        ];
110
    }
111
112
    /**
113
     * @return string[]
114
     */
115
    protected function ruleSingular(): array
116
    {
117
        return [
118
            '/(quiz)zes$/i' => "$1",
119
            '/(matr)ices$/i' => "$1ix",
120
            '/(vert|ind)ices$/i' => "$1ex",
121
            '/^(ox)en$/i' => "$1",
122
            '/(alias)es$/i' => "$1",
123
            '/(octop|vir)i$/i' => "$1us",
124
            '/(cris|ax|test)es$/i' => "$1is",
125
            '/(shoe)s$/i' => "$1",
126
            '/(o)es$/i' => "$1",
127
            '/(bus)es$/i' => "$1",
128
            '/([m|l])ice$/i' => "$1ouse",
129
            '/(x|ch|ss|sh)es$/i' => "$1",
130
            '/(m)ovies$/i' => "$1ovie",
131
            '/(s)eries$/i' => "$1eries",
132
            '/([^aeiouy]|qu)ies$/i' => "$1y",
133
            '/([lr])ves$/i' => "$1f",
134
            '/(tive)s$/i' => "$1",
135
            '/(hive)s$/i' => "$1",
136
            '/(li|wi|kni)ves$/i' => "$1fe",
137
            '/(shea|loa|lea|thie)ves$/i' => "$1f",
138
            '/(^analy)ses$/i' => "$1sis",
139
            '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => "$1$2sis",
140
            '/([ti])a$/i' => "$1um",
141
            '/(n)ews$/i' => "$1ews",
142
            '/(h|bl)ouses$/i' => "$1ouse",
143
            '/(corpse)s$/i' => "$1",
144
            '/(us)es$/i' => "$1",
145
            '/s$/i' => ""
146
        ];
147
    }
148
149
    /**
150
     * @return string[]
151
     */
152
    protected function ruleUncountable(): array
153
    {
154
        return [
155
            'adulthood',
156
            'advice',
157
            'agenda',
158
            'aid',
159
            'aircraft',
160
            'alcohol',
161
            'ammo',
162
            'analytics',
163
            'anime',
164
            'athletics',
165
            'audio',
166
            'bison',
167
            'blood',
168
            'bream',
169
            'buffalo',
170
            'butter',
171
            'carp',
172
            'cash',
173
            'chassis',
174
            'chess',
175
            'clothing',
176
            'cod',
177
            'commerce',
178
            'cooperation',
179
            'corps',
180
            'debris',
181
            'diabetes',
182
            'digestion',
183
            'elk',
184
            'energy',
185
            'equipment',
186
            'excretion',
187
            'expertise',
188
            'firmware',
189
            'flounder',
190
            'fun',
191
            'gallows',
192
            'garbage',
193
            'graffiti',
194
            'hardware',
195
            'headquarters',
196
            'health',
197
            'herpes',
198
            'highjinks',
199
            'homework',
200
            'housework',
201
            'information',
202
            'jeans',
203
            'justice',
204
            'kudos',
205
            'labour',
206
            'literature',
207
            'machinery',
208
            'mackerel',
209
            'mail',
210
            'media',
211
            'mews',
212
            'money',
213
            'moose',
214
            'music',
215
            'mud',
216
            'manga',
217
            'news',
218
            'only',
219
            'personnel',
220
            'pike',
221
            'plankton',
222
            'pliers',
223
            'police',
224
            'pollution',
225
            'premises',
226
            'rain',
227
            'research',
228
            'rice',
229
            'salmon',
230
            'scissors',
231
            'series',
232
            'sewage',
233
            'shambles',
234
            'shrimp',
235
            'software',
236
            'species',
237
            'staff',
238
            'swine',
239
            'tennis',
240
            'thanks',
241
            'traffic',
242
            'transportation',
243
            'trout',
244
            'tuna',
245
            'wealth',
246
            'welfare',
247
            'whiting',
248
            'wildebeest',
249
            'wildlife',
250
            'you',
251
            '/pok[eé]mon$/i',
252
            '/[^aeiou]ese$/i',
253
            '/deer$/i',
254
            '/fish$/i',
255
            '/measles$/i',
256
            '/o[iu]s$/i',
257
            '/pox$/i',
258
            '/sheep$/i'
259
        ];
260
    }
261
}