Completed
Push — master ( 622740...e78b73 )
by f
01:58
created

src/English/NounPluralization.php (9 issues)

Upgrade to new PHP Analysis Engine

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
Comprehensibility Best Practice introduced by
The expression \morphos\S::lower($word); of type string|false adds false to the return on line 51 which is incompatible with the return type documented by morphos\English\NounPluralization::pluralize of type string. It seems like you forgot to handle an error condition.
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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

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 false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
67
            }
68
        } else {
69 17
            return $word.'s';
70
        }
71
    }
72
}
73