These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace morphos\English; |
||
3 | |||
4 | use morphos\S; |
||
5 | |||
6 | class NounPluralization extends \morphos\NounPluralization |
||
7 | { |
||
8 | private static $exceptions = [ |
||
9 | 'chief' => 'chiefs', |
||
10 | 'basis' => 'bases', |
||
11 | 'crisis' => 'crises', |
||
12 | 'radius' => 'radii', |
||
13 | 'nucleus' => 'nuclei', |
||
14 | 'curriculum' => 'curricula', |
||
15 | 'man' => 'men', |
||
16 | 'woman' => 'women', |
||
17 | 'child' => 'children', |
||
18 | 'foot' => 'feet', |
||
19 | 'tooth' => 'teeth', |
||
20 | 'ox' => 'oxen', |
||
21 | 'goose' => 'geese', |
||
22 | 'mouse' => 'mice' |
||
23 | ]; |
||
24 | |||
25 | private static $without_paired_form = [ |
||
26 | 'knowledge', |
||
27 | 'progress', |
||
28 | 'advise', |
||
29 | 'ink', |
||
30 | 'money', |
||
31 | 'scissors', |
||
32 | 'spectacles', |
||
33 | 'trousers', |
||
34 | ]; |
||
35 | |||
36 | public static $consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'z', 'w']; |
||
37 | |||
38 | /** |
||
39 | * @param $word |
||
40 | * @param int $count |
||
41 | * @return string |
||
42 | */ |
||
43 | 47 | public static function pluralize($word, $count = 2) |
|
44 | { |
||
45 | 47 | if ($count == 1) { |
|
46 | 7 | return $word; |
|
47 | } |
||
48 | |||
49 | 46 | $word = S::lower($word); |
|
50 | 46 | if (in_array($word, static::$without_paired_form)) { |
|
0 ignored issues
–
show
|
|||
51 | 8 | return $word; |
|
52 | 38 | } elseif (isset(static::$exceptions[$word])) { |
|
0 ignored issues
–
show
Since
$exceptions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $exceptions to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
53 | 14 | return static::$exceptions[$word]; |
|
0 ignored issues
–
show
Since
$exceptions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $exceptions to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
54 | } |
||
55 | |||
56 | 24 | if (in_array(S::slice($word, -1), ['s', 'x']) || in_array(S::slice($word, -2), array('sh', 'ch'))) { |
|
57 | 2 | return $word.'es'; |
|
58 | 22 | } elseif (S::slice($word, -1) == 'o') { |
|
59 | 1 | return $word.'es'; |
|
60 | 21 | } elseif (S::slice($word, -1) == 'y' && in_array(S::slice($word, -2, -1), static::$consonants)) { |
|
61 | 2 | return S::slice($word, 0, -1).'ies'; |
|
62 | 19 | } elseif (S::slice($word, -2) == 'fe' || S::slice($word, -1) == 'f') { |
|
63 | 2 | if (S::slice($word, -1) == 'f') { |
|
64 | 1 | return S::slice($word, 0, -1).'ves'; |
|
65 | } else { |
||
66 | 1 | return S::slice($word, 0, -2).'ves'; |
|
67 | } |
||
68 | } else { |
||
69 | 17 | return $word.'s'; |
|
70 | } |
||
71 | } |
||
72 | } |
||
73 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: