wapmorgan /
Morphos
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); |
|
|
0 ignored issues
–
show
Bug
Compatibility
introduced
by
Loading history...
|
|||
| 50 | 46 | if (in_array($word, self::$without_paired_form)) { |
|
| 51 | 8 | return $word; |
|
| 52 | 38 | } elseif (isset(self::$exceptions[$word])) { |
|
| 53 | 14 | return self::$exceptions[$word]; |
|
| 54 | } |
||
| 55 | |||
| 56 | 24 | if (in_array(S::slice($word, -1), ['s', 'x']) || in_array(S::slice($word, -2), array('sh', 'ch'))) { |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 57 | 2 | return $word.'es'; |
|
| 58 | 22 | } elseif (S::slice($word, -1) == 'o') { |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 59 | 1 | return $word.'es'; |
|
| 60 | 21 | } elseif (S::slice($word, -1) == 'y' && in_array(S::slice($word, -2, -1), self::$consonants)) { |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 61 | 2 | return S::slice($word, 0, -1).'ies'; |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 62 | 19 | } elseif (S::slice($word, -2) == 'fe' || S::slice($word, -1) == 'f') { |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 63 | 2 | if (S::slice($word, -1) == 'f') { |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 64 | 1 | return S::slice($word, 0, -1).'ves'; |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 65 | } else { |
||
| 66 | 1 | return S::slice($word, 0, -2).'ves'; |
|
|
0 ignored issues
–
show
It seems like
$word defined by \morphos\S::lower($word) on line 49 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 67 | } |
||
| 68 | } else { |
||
| 69 | 17 | return $word.'s'; |
|
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 |