Completed
Push — master ( b5bb9d...38f7c0 )
by f
02:02
created

src/Russian/GeographicalNamesInflection.php (42 issues)

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

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\Russian;
3
4
use morphos\S;
5
6
/**
7
 * Rules are from: https://ru.wikipedia.org/wiki/%D0%A1%D0%BA%D0%BB%D0%BE%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5_%D0%B3%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D1%84%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D1%85_%D0%BD%D0%B0%D0%B7%D0%B2%D0%B0%D0%BD%D0%B8%D0%B9_%D0%B2_%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D0%BC_%D1%8F%D0%B7%D1%8B%D0%BA%D0%B5
8
 */
9
class GeographicalNamesInflection extends \morphos\BaseInflection implements Cases
10
{
11
    use RussianLanguage, CasesHelper;
12
13
    protected static $abbreviations = [
14
        'сша',
15
        'оаэ',
16
        'ссср',
17
        'юар',
18
    ];
19
20
    protected static $delimiters = [
21
        ' ',
22
        '-на-',
23
        '-',
24
    ];
25
26
    protected static $ovAbnormalExceptions = [
27
        'осташков',
28
    ];
29
30
    protected static $immutableParts = [
31
        'санкт',
32
    ];
33
34
    protected static $runawayVowelsExceptions = [
35
        'торжо*к',
36
        'волоче*к',
37
        'оре*л',
38
    ];
39
40
    /**
41
     * @return array|bool
42
     */
43 9 View Code Duplication
    protected static function getRunAwayVowelsList()
44
    {
45 9
        $runawayVowelsNormalized = [];
46 9
        foreach (self::$runawayVowelsExceptions as $word) {
47 9
            $runawayVowelsNormalized[str_replace('*', null, $word)] = S::indexOf($word, '*') - 1;
48
        }
49 9
        return $runawayVowelsNormalized;
50
    }
51
52
    /**
53
     * Проверяет, склоняемо ли название
54
     * @param string $name Название
55
     * @return bool
56
     */
57 2
    public static function isMutable($name)
58
    {
59 2
        $name = S::lower($name);
60
61
        // // ends with 'ы' or 'и': plural form
62
        // if (in_array(S::slice($name, -1), array('и', 'ы')))
63
        //     return false;
64
65 2
        if (in_array($name, self::$abbreviations, true) || in_array($name, self::$immutableParts, true)) {
66 2
            return false;
67
        }
68
69
        if (strpos($name, ' ') !== false) {
70
            // explode() is not applicable because Geographical unit may have few words
71
            $first_part = S::slice($name, 0, S::findFirstPosition($name, ' '));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 59 can also be of type boolean; however, morphos\S::findFirstPosition() 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...
It seems like $name defined by \morphos\S::lower($name) on line 59 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...
72
            $last_part = S::slice($name,
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 59 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...
73
                S::findLastPosition($name, ' ') + 1);
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 59 can also be of type boolean; however, morphos\S::findLastPosition() 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...
74
75
            // город N, село N, хутор N, район N, поселок N, округ N, республика N
76
            // N область, N край
77
            if (in_array($first_part, ['город', 'село', 'хутор', 'район', 'поселок', 'округ', 'республика'], true)
78
                || in_array($last_part, ['край', 'область'], true)) {
79
                return true;
80
            }
81
82
            // пгт N
83
            if ($first_part === 'пгт')
84
                return false;
85
        }
86
87
        // ends with 'е' or 'о', but not with 'ово/ёво/ево/ино/ыно'
88
        if (in_array(S::slice($name, -1), ['е', 'о'], true) && !in_array(S::slice($name, -3, -1), ['ов', 'ёв', 'ев', 'ин', 'ын'], true)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 59 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...
89
            return false;
90
        }
91
        return true;
92
    }
93
94
    /**
95
     * Получение всех форм названия
96
     * @param string $name
97
     * @return array
98
     * @throws \Exception
99
     */
100 39
    public static function getCases($name)
101
    {
102 39
        $name = S::lower($name);
103
104 39
        if (in_array($name, self::$immutableParts, true)) {
105 1
            return array_fill_keys([self::IMENIT, self::RODIT, self::DAT, self::VINIT, self::TVORIT, self::PREDLOJ], S::name($name));
106
        }
107
108 39
        if (strpos($name, ' ') !== false) {
109 9
            $first_part = S::slice($name, 0, S::findFirstPosition($name, ' '));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 can also be of type boolean; however, morphos\S::findFirstPosition() 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...
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
110
            // город N, село N, хутор N, пгт N
111 9
            if (in_array($first_part, ['город', 'село', 'хутор', 'пгт', 'район', 'поселок', 'округ', 'республика'], true)) {
112 3
                if ($first_part !== 'пгт')
113 3
                    return self::composeCasesFromWords([
114 3
                        $first_part !== 'республика'
115 2
                            ? NounDeclension::getCases($first_part)
116 3
                            : array_map(['\\morphos\\S', 'name'], NounDeclension::getCases($first_part)),
117 3
                        array_fill_keys(self::getAllCases(), S::name(S::slice($name, S::length($first_part) + 1)))
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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
                    ]);
119
                else
120
                    return array_fill_keys([self::IMENIT, self::RODIT, self::DAT, self::VINIT, self::TVORIT, self::PREDLOJ], 'пгт '.S::name(S::slice($name, 4)));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
121
            }
122
123 6
            $last_part = S::slice($name,
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
124 6
                S::findLastPosition($name, ' ') + 1);
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 can also be of type boolean; however, morphos\S::findLastPosition() 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...
125
            // N область, N край
126 6
            if (in_array($last_part, ['край', 'область'], true)) {
127 2
                return self::composeCasesFromWords([static::getCases(S::slice($name, 0, S::findLastPosition($name, ' '))), NounDeclension::getCases($last_part)]);
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 can also be of type boolean; however, morphos\S::findLastPosition() 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...
It seems like $name defined by \morphos\S::lower($name) on line 102 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
            }
129
        }
130
131
        // Сложное название через пробел, '-' или '-на-'
132 36
        foreach (self::$delimiters as $delimiter) {
133 36
            if (strpos($name, $delimiter) !== false) {
134 6
                $parts = explode($delimiter, $name);
135 6
                $result = [];
136 6
                foreach ($parts as $i => $part) {
137 6
                    $result[$i] = static::getCases($part);
138
                }
139 36
                return self::composeCasesFromWords($result, $delimiter);
140
            }
141
        }
142
143 36
        if (!in_array($name, self::$abbreviations, true)) {
144 34
            switch (S::slice($name, -2)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
145
                // Нижний, Русский
146 34
                case 'ий':
147 3
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
148
                    return [
149 3
                        self::IMENIT => $prefix.'ий',
150 3
                        self::RODIT => $prefix.(self::isVelarConsonant(S::slice($name, -3, -2)) ? 'ого' : 'его'),
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
151 3
                        self::DAT => $prefix.(self::isVelarConsonant(S::slice($name, -3, -2)) ? 'ому' : 'ему'),
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
152 3
                        self::VINIT => $prefix.'ий',
153 3
                        self::TVORIT => $prefix.'им',
154 3
                        self::PREDLOJ => $prefix.(self::chooseEndingBySonority($prefix, 'ем', 'ом')),
0 ignored issues
show
It seems like $prefix defined by \morphos\S::name(\morphos\S::slice($name, 0, -2)) on line 147 can also be of type boolean; however, morphos\Russian\RussianL...hooseEndingBySonority() 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...
155
                    ];
156
157
                // Ростовская
158 33
                case 'ая':
159 1
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
160
                    return [
161 1
                        self::IMENIT => $prefix.'ая',
162 1
                        self::RODIT => $prefix.'ой',
163 1
                        self::DAT => $prefix.'ой',
164 1
                        self::VINIT => $prefix.'ую',
165 1
                        self::TVORIT => $prefix.'ой',
166 1
                        self::PREDLOJ => $prefix.'ой',
167
                    ];
168
169
                // Россошь
170 32
                case 'шь':
171 1
                    $prefix = S::name(S::slice($name, 0, -1));
172
                    return [
173 1
                        self::IMENIT => $prefix.'ь',
174 1
                        self::RODIT => $prefix.'и',
175 1
                        self::DAT => $prefix.'и',
176 1
                        self::VINIT => $prefix.'ь',
177 1
                        self::TVORIT => $prefix.'ью',
178 1
                        self::PREDLOJ => $prefix.'и',
179
                    ];
180
181
                // Грозный, Благодарный
182 31
                case 'ый':
183 2
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
184
                    return [
185 2
                        self::IMENIT => $prefix.'ый',
186 2
                        self::RODIT => $prefix.'ого',
187 2
                        self::DAT => $prefix.'ому',
188 2
                        self::VINIT => $prefix.'ый',
189 2
                        self::TVORIT => $prefix.'ым',
190 2
                        self::PREDLOJ => $prefix.'ом',
191
                    ];
192
193
                // Ставрополь, Ярославль, Электросталь
194 29
                case 'ль':
195 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
196
197 2 View Code Duplication
                    if ($name === 'электросталь')
198
                        return [
199 1
                            self::IMENIT => $prefix.'ь',
200 1
                            self::RODIT => $prefix.'и',
201 1
                            self::DAT => $prefix.'и',
202 1
                            self::VINIT => $prefix.'ь',
203 1
                            self::TVORIT => $prefix.'ью',
204 1
                            self::PREDLOJ => $prefix.'и',
205
                        ];
206
207
                    return [
208 1
                        self::IMENIT => $prefix.'ь',
209 1
                        self::RODIT => $prefix.'я',
210 1
                        self::DAT => $prefix.'ю',
211 1
                        self::VINIT => $prefix.'ь',
212 1
                        self::TVORIT => $prefix.'ем',
213 1
                        self::PREDLOJ => $prefix.'е',
214
                    ];
215
216
                // Тверь, Анадырь
217 27
                case 'рь':
218 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
219 2
                    $last_vowel = S::slice($prefix, -2, -1);
0 ignored issues
show
It seems like $prefix defined by \morphos\S::name(\morphos\S::slice($name, 0, -1)) on line 218 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...
220
                    return [
221 2
                        self::IMENIT => $prefix . 'ь',
222 2
                        self::RODIT => $prefix . (self::isBinaryVowel($last_vowel) ? 'и' : 'я'),
223 2
                        self::DAT => $prefix . (self::isBinaryVowel($last_vowel) ? 'и' : 'ю'),
224 2
                        self::VINIT => $prefix . 'ь',
225 2
                        self::TVORIT => $prefix . (self::isBinaryVowel($last_vowel) ? 'ью' : 'ем'),
226 2
                        self::PREDLOJ => $prefix . (self::isBinaryVowel($last_vowel) ? 'и' : 'е'),
227
                    ];
228
229
                // Березники, Ессентуки
230 25
                case 'ки':
231 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
232
                    return [
233 2
                        self::IMENIT => $prefix . 'и',
234 2
                        self::RODIT => $name == 'луки' ? $prefix : $prefix . 'ов',
235 2
                        self::DAT => $prefix . 'ам',
236 2
                        self::VINIT => $prefix . 'и',
237 2
                        self::TVORIT => $prefix . 'ами',
238 2
                        self::PREDLOJ => $prefix . 'ах',
239
                    ];
240
241
                // Пермь, Кемь
242 24
                case 'мь':
243 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
244
                    return [
245 1
                        self::IMENIT => $prefix . 'ь',
246 1
                        self::RODIT => $prefix . 'и',
247 1
                        self::DAT => $prefix . 'и',
248 1
                        self::VINIT => $prefix . 'ь',
249 1
                        self::TVORIT => $prefix . 'ью',
250 1
                        self::PREDLOJ => $prefix . 'и',
251
                    ];
252
253
                // Рязань, Назрань
254 23
                case 'нь':
255 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
256
                    return [
257 1
                        self::IMENIT => $prefix . 'ь',
258 1
                        self::RODIT => $prefix . 'и',
259 1
                        self::DAT => $prefix . 'и',
260 1
                        self::VINIT => $prefix . 'ь',
261 1
                        self::TVORIT => $prefix . 'ью',
262 1
                        self::PREDLOJ => $prefix . 'и',
263
                    ];
264
265
                // Набережные
266 22
                case 'ые':
267 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
268
                    return [
269 1
                        self::IMENIT => $prefix . 'е',
270 1
                        self::RODIT => $prefix . 'х',
271 1
                        self::DAT => $prefix . 'м',
272 1
                        self::VINIT => $prefix . 'е',
273 1
                        self::TVORIT => $prefix . 'ми',
274 1
                        self::PREDLOJ => $prefix . 'х',
275
                    ];
276
277
                // Челны
278 22
                case 'ны':
279 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
280
                    return [
281 1
                        self::IMENIT => $prefix . 'ы',
282 1
                        self::RODIT => $prefix . 'ов',
283 1
                        self::DAT => $prefix . 'ам',
284 1
                        self::VINIT => $prefix . 'ы',
285 1
                        self::TVORIT => $prefix . 'ами',
286 1
                        self::PREDLOJ => $prefix . 'ах',
287
                    ];
288
289
                // Великие
290 21
                case 'ие':
291 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
292
                    return [
293 1
                        self::IMENIT => $prefix.'е',
294 1
                        self::RODIT => $prefix.'х',
295 1
                        self::DAT => $prefix.'м',
296 1
                        self::VINIT => $prefix.'е',
297 1
                        self::TVORIT => $prefix.'ми',
298 1
                        self::PREDLOJ => $prefix.'х',
299
                    ];
300
301
                // Керчь
302 20
                case 'чь':
303 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
304
                    return [
305 1
                        self::IMENIT => $prefix.'ь',
306 1
                        self::RODIT => $prefix.'и',
307 1
                        self::DAT => $prefix.'и',
308 1
                        self::VINIT => $prefix.'ь',
309 1
                        self::TVORIT => $prefix.'ью',
310 1
                        self::PREDLOJ => $prefix.'и',
311
                    ];
312
            }
313
314 19
            switch (S::slice($name, -1)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
315 19
                case 'р':
316
                    // Бор
317
                    $prefix = S::name(S::slice($name, 0, -1));
318
                    return [
319
                        self::IMENIT => $prefix.'р',
320
                        self::RODIT => $prefix.'ра',
321
                        self::DAT => $prefix.'ру',
322
                        self::VINIT => $prefix.'р',
323
                        self::TVORIT => $prefix.'ром',
324
                        self::PREDLOJ => $prefix.'ру',
325
                    ];
326
327 19 View Code Duplication
                case 'ы':
328
                    // Чебоксары, Шахты
329 1
                    $prefix = S::name(S::slice($name, 0, -1));
330
                    return [
331 1
                        self::IMENIT => $prefix.'ы',
332 1
                        self::RODIT => $prefix,
333 1
                        self::DAT => $prefix.'ам',
334 1
                        self::VINIT => $prefix.'ы',
335 1
                        self::TVORIT => $prefix.'ами',
336 1
                        self::PREDLOJ => $prefix.'ах',
337
                    ];
338
339 18
                case 'я':
340
                    // Азия
341 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
342
                    return [
343 1
                        self::IMENIT => S::name($name),
344 1
                        self::RODIT => $prefix.'и',
345 1
                        self::DAT => $prefix.'и',
346 1
                        self::VINIT => $prefix.'ю',
347 1
                        self::TVORIT => $prefix.'ей',
348 1
                        self::PREDLOJ => $prefix.'и',
349
                    ];
350
351 17 View Code Duplication
                case 'а':
352
                    // Москва, Рига
353 5
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
354
                    return [
355 5
                        self::IMENIT => $prefix.'а',
356 5
                        self::RODIT => $prefix.(self::isVelarConsonant(S::slice($name, -2, -1)) ? 'и' : 'ы'),
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
357 5
                        self::DAT => $prefix.'е',
358 5
                        self::VINIT => $prefix.'у',
359 5
                        self::TVORIT => $prefix.'ой',
360 5
                        self::PREDLOJ => $prefix.'е',
361
                    ];
362
363 12
                case 'й':
364
                    // Ишимбай
365 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
366
                    return [
367 2
                        self::IMENIT => $prefix . 'й',
368 2
                        self::RODIT => $prefix . 'я',
369 2
                        self::DAT => $prefix . 'ю',
370 2
                        self::VINIT => $prefix . 'й',
371 2
                        self::TVORIT => $prefix . 'ем',
372 2
                        self::PREDLOJ => $prefix . 'е',
373
                    ];
374
            }
375
376 10
            if (self::isConsonant(S::slice($name,  -1)) && !in_array($name, self::$ovAbnormalExceptions, true)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
377 9
                $runaway_vowels_list = static::getRunAwayVowelsList();
378
379
                // if run-away vowel in name
380 9
                if (isset($runaway_vowels_list[$name])) {
381 3
                    $runaway_vowel_offset = $runaway_vowels_list[$name];
382 3
                    $prefix = S::name(S::slice($name, 0, $runaway_vowel_offset) . S::slice($name, $runaway_vowel_offset + 1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
383
                } else {
384 6
                    $prefix = S::name($name);
385
                }
386
387
                // Париж, Валаам, Киев
388
                return [
389 9
                    self::IMENIT => S::name($name),
390 9
                    self::RODIT => $prefix . 'а',
391 9
                    self::DAT => $prefix . 'у',
392 9
                    self::VINIT => S::name($name),
393 9
                    self::TVORIT => $prefix . (self::isVelarConsonant(S::slice($name, -2, -1)) ? 'ем' : 'ом'),
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
394 9
                    self::PREDLOJ => $prefix . 'е',
395
                ];
396
            }
397
398
            // ов, ово, ёв, ёво, ев, ево, ...
399 2
            $suffixes = ['ов', 'ёв', 'ев', 'ин', 'ын'];
400 2
            if ((in_array(S::slice($name, -1), ['е', 'о'], true) && in_array(S::slice($name, -3, -1), $suffixes, true)) || in_array(S::slice($name, -2), $suffixes, true)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
401
                // ово, ёво, ...
402 1
                if (in_array(S::slice($name, -3, -1), $suffixes, true)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
403
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
404
                }
405
                // ов, её, ...
406 1
                elseif (in_array(S::slice($name, -2), $suffixes, true)) {
0 ignored issues
show
It seems like $name defined by \morphos\S::lower($name) on line 102 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...
407 1
                    $prefix = S::name($name);
408
                }
409
                return [
410 1
                    self::IMENIT => S::name($name),
411 1
                    self::RODIT => $prefix.'а',
412 1
                    self::DAT => $prefix.'у',
413 1
                    self::VINIT => S::name($name),
414 1
                    self::TVORIT => $prefix.'ым',
415 1
                    self::PREDLOJ => $prefix.'е',
416
                ];
417
            }
418
        }
419
420
        // if no rules matches or name is immutable
421 3
        $name = in_array($name, self::$abbreviations, true) ? S::upper($name) : S::name($name);
422 3
        return array_fill_keys([self::IMENIT, self::RODIT, self::DAT, self::VINIT, self::TVORIT, self::PREDLOJ], $name);
423
    }
424
425
    /**
426
     * Получение одной формы (падежа) названия.
427
     * @param string $name  Название
428
     * @param integer $case Падеж. Одна из констант \morphos\Russian\Cases или \morphos\Cases.
429
     * @see \morphos\Russian\Cases
430
     * @return string
431
     * @throws \Exception
432
     */
433
    public static function getCase($name, $case)
434
    {
435
        $case = self::canonizeCase($case);
436
        $forms = self::getCases($name);
437
        return $forms[$case];
438
    }
439
}