Completed
Push — master ( 15bafb...0d947c )
by f
11:24
created

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