Completed
Push — master ( 30b420...9a3fa7 )
by f
01:34
created

LastNamesInflection::getCases()   F

Complexity

Conditions 19
Paths 48

Size

Total Lines 130

Duplication

Lines 27
Ratio 20.77 %

Code Coverage

Tests 86
CRAP Score 19.0005

Importance

Changes 0
Metric Value
cc 19
nc 48
nop 2
dl 27
loc 130
ccs 86
cts 87
cp 0.9885
crap 19.0005
rs 3.6133
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
namespace morphos\Russian;
3
4
use morphos\S;
5
6
/**
7
 * Rules are from http://gramma.ru/SPR/?id=2.8
8
 */
9
class LastNamesInflection extends \morphos\NamesInflection implements Cases
10
{
11
    use RussianLanguage, CasesHelper;
12
13
    protected static $menPostfixes = ['ов', 'ев' ,'ин' ,'ын', 'ой', 'ий'];
14
    protected static $womenPostfixes = ['ва', 'на', 'ая', 'яя'];
15
16
    /**
17
     * @param $name
18
     * @param null $gender
19
     * @return bool
20
     */
21 62
    public static function isMutable($name, $gender = null)
22
    {
23 62
        $name = S::lower($name);
24 62
        if ($gender === null) {
25
            $gender = static::detectGender($name);
26
        }
27
        // составная фамилия - разбить на части и проверить по отдельности
28 62
        if (strpos($name, '-') !== false) {
29 3
            foreach (explode('-', $name) as $part) {
30 3
                if (static::isMutable($part, $gender))
0 ignored issues
show
Bug introduced by
It seems like $gender defined by static::detectGender($name) on line 25 can also be of type string; however, morphos\Russian\LastNamesInflection::isMutable() does only seem to accept null, 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...
31 3
                    return true;
32
            }
33
            return false;
34
        }
35
36 62 View Code Duplication
        if (in_array(S::slice($name, -1), ['а', 'я'], true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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...
37 24
            return true;
38
        }
39
40 39
        if ($gender == static::MALE) {
41
            // Несклоняемые фамилии (Фоминых, Седых / Стецко, Писаренко)
42 38 View Code Duplication
            if (in_array(S::slice($name, -2), ['ых', 'ко'], true))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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...
43 1
                return false;
44
45
            // Несклоняемые, образованные из родительного падежа личного или прозвищного имени главы семьи
46
            // суффиксы: ово, аго
47 37 View Code Duplication
            if (in_array(S::slice($name, -3), ['ово', 'аго'], true))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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...
48 1
                return false;
49
50
            // Типичные суффикс мужских фамилий
51 36
            if (in_array(S::slice($name, -2), ['ов', 'ев', 'ин', 'ын', 'ий', 'ой'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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...
52 13
                return true;
53
            }
54
55
            // Согласная на конце
56 23
            if (static::isConsonant(S::slice($name, -1))) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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 15
                return true;
58
            }
59
60
            // Мягкий знак на конце
61 8
            if (S::slice($name, -1) == 'ь') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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 8
                return true;
63
            }
64
65 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
66
            // Типичные суффиксы женских фамилий
67 1
            if (in_array(S::slice($name, -2), ['ва', 'на', 'ая'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 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...
68
                return true;
69
            }
70
        }
71
72 3
        return false;
73
    }
74
75
    /**
76
     * @param $name
77
     * @return null|string
78
     */
79 23
    public static function detectGender($name)
80
    {
81 23
        $name = S::lower($name);
82 23
        if (in_array(S::slice($name, -2), static::$menPostfixes, true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 81 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...
83 6
            return static::MALE;
84
        }
85 18
        if (in_array(S::slice($name, -2), static::$womenPostfixes, true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 81 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...
86 5
            return static::FEMALE;
87
        }
88
89 13
        return null;
90
    }
91
92
    /**
93
     * @param $name
94
     * @param null|string $gender
95
     * @return array
96
     */
97 37
    public static function getCases($name, $gender = null)
98
    {
99 37
        $name = S::lower($name);
100 37
        if ($gender === null) {
101
            $gender = static::detectGender($name);
102
        }
103
104
        // составная фамилия - разбить на части и склонять по отдельности
105 37
        if (strpos($name, '-') !== false) {
106 3
            $parts = explode('-', $name);
107 3
            $cases = [];
0 ignored issues
show
Unused Code introduced by
$cases is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108 3
            foreach ($parts as $i => $part) {
109 3
                $parts[$i] = static::getCases($part, $gender);
110
            }
111
112 3
            return static::composeCasesFromWords($parts, '-');
113
        }
114
115 37
        if (static::isMutable($name, $gender)) {
0 ignored issues
show
Bug introduced by
It seems like $gender can also be of type string; however, morphos\Russian\LastNamesInflection::isMutable() does only seem to accept null, 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...
116 36
            if ($gender == static::MALE) {
117 23
                if (in_array(S::slice($name, -2), ['ов', 'ев', 'ин', 'ын'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
118 5
                    $prefix = S::name($name);
119
                    return [
120 5
                        static::IMENIT => $prefix,
121 5
                        static::RODIT => $prefix.'а',
122 5
                        static::DAT => $prefix.'у',
123 5
                        static::VINIT => $prefix.'а',
124 5
                        static::TVORIT => $prefix.'ым',
125 5
                        static::PREDLOJ => $prefix.'е'
126
                    ];
127 18 View Code Duplication
                } elseif (in_array(S::slice($name, -4), ['ский', 'ской', 'цкий', 'цкой'], true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
128 1
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
129
                    return [
130 1
                        static::IMENIT => S::name($name),
131 1
                        static::RODIT => $prefix.'ого',
132 1
                        static::DAT => $prefix.'ому',
133 1
                        static::VINIT => $prefix.'ого',
134 1
                        static::TVORIT => $prefix.'им',
135 1
                        static::PREDLOJ => $prefix.'ом'
136
                    ];
137
                // Верхний / Убогий / Толстой
138
                // Верхнего / Убогого / Толстого
139
                // Верхнему / Убогому / Толстому
140
                // Верхним / Убогим / Толстым
141
                // О Верхнем / Об Убогом / О Толстом
142 17
                } else if (in_array(S::slice($name, -2), ['ой', 'ый', 'ий'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
143 3
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
144
                    return [
145 3
                        static::IMENIT => S::name($name),
146 3
                        static::RODIT => $prefix.'ого',
147 3
                        static::DAT => $prefix.'ому',
148 3
                        static::VINIT => $prefix.'ого',
149 3
                        static::TVORIT => $prefix.'ым',
150 17
                        static::PREDLOJ => $prefix.'ом'
151
                    ];
152
                }
153
154
            } else {
155 13 View Code Duplication
                if (in_array(S::slice($name, -3), ['ова', 'ева', 'ина', 'ына'], true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
156 5
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
157
                    return [
158 5
                        static::IMENIT => S::name($name),
159 5
                        static::RODIT => $prefix.'ой',
160 5
                        static::DAT => $prefix.'ой',
161 5
                        static::VINIT => $prefix.'у',
162 5
                        static::TVORIT => $prefix.'ой',
163 5
                        static::PREDLOJ => $prefix.'ой'
164
                    ];
165
                }
166
167 8
                if (in_array(S::slice($name, -2), ['ая'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
168 3
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
169
                    return [
170 3
                        static::IMENIT => S::name($name),
171 3
                        static::RODIT => $prefix.'ой',
172 3
                        static::DAT => $prefix.'ой',
173 3
                        static::VINIT => $prefix.'ую',
174 3
                        static::TVORIT => $prefix.'ой',
175 3
                        static::PREDLOJ => $prefix.'ой'
176
                    ];
177
                }
178
            }
179
180 19
            if (S::slice($name, -1) == 'я') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
181 1
                $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
182
                return [
183 1
                    static::IMENIT => S::name($name),
184 1
                    static::RODIT => $prefix.'и',
185 1
                    static::DAT => $prefix.'е',
186 1
                    static::VINIT => $prefix.'ю',
187 1
                    static::TVORIT => $prefix.'ей',
188 1
                    static::PREDLOJ => $prefix.'е'
189
                ];
190 18
            } elseif (S::slice($name, -1) == 'а') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
191 6
                $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
192
                return [
193 6
                    static::IMENIT => S::name($name),
194 6
                    static::RODIT => $prefix.(static::isDeafConsonant(S::slice($name, -2, -1)) || S::slice($name, -2)
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
195 6
                        == 'га' ? 'и' : 'ы'),
196 6
                    static::DAT => $prefix.'е',
197 6
                    static::VINIT => $prefix.'у',
198 6
                    static::TVORIT => $prefix.'ой',
199 6
                    static::PREDLOJ => $prefix.'е'
200
                ];
201 12
            } elseif (static::isConsonant(S::slice($name, -1)) && S::slice($name, -2) != 'ых') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
202 9
                $prefix = S::name($name);
203
                return [
204 9
                    static::IMENIT => S::name($name),
205 9
                    static::RODIT => $prefix.'а',
206 9
                    static::DAT => $prefix.'у',
207 9
                    static::VINIT => $prefix.'а',
208 9
                    static::TVORIT => $prefix.'ом',
209 9
                    static::PREDLOJ => $prefix.'е'
210
                ];
211 3
            } elseif (S::slice($name, -1) == 'ь' && $gender == static::MALE) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
212 3
                $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 99 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...
213
                return [
214 3
                    static::IMENIT => S::name($name),
215 3
                    static::RODIT => $prefix.'я',
216 3
                    static::DAT => $prefix.'ю',
217 3
                    static::VINIT => $prefix.'я',
218 3
                    static::TVORIT => $prefix.'ем',
219 3
                    static::PREDLOJ => $prefix.'е'
220
                ];
221
            }
222
        }
223
224 2
        $name = S::name($name);
225 2
        return array_fill_keys([static::IMENIT, static::RODIT, static::DAT, static::VINIT, static::TVORIT, static::PREDLOJ], $name);
226
    }
227
228
    /**
229
     * @param $name
230
     * @param $case
231
     * @param null $gender
232
     * @return string
233
     * @throws \Exception
234
     */
235 6
    public static function getCase($name, $case, $gender = null)
236
    {
237 6
        if (!static::isMutable($name, $gender)) {
238
            return $name;
239
        } else {
240 6
            $case = static::canonizeCase($case);
241 6
            $forms = static::getCases($name, $gender);
242 6
            return $forms[$case];
243
        }
244
    }
245
}
246