Completed
Push — master ( c2a346...58101e )
by f
02:00
created

GeographicalNamesInflection   B

Complexity

Total Complexity 52

Size/Duplication

Total Lines 353
Duplicated Lines 3.12 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 91.44%

Importance

Changes 0
Metric Value
dl 11
loc 353
ccs 171
cts 187
cp 0.9144
rs 7.44
c 0
b 0
f 0
wmc 52
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
B isMutable() 0 33 9
F getCases() 11 267 42
A getCase() 0 6 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like GeographicalNamesInflection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GeographicalNamesInflection, and based on these observations, apply Extract Interface, too.

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
     * @param string $name Название
37
     * @return bool
38
     */
39 2
    public static function isMutable($name)
40
    {
41 2
        $name = S::lower($name);
42
43
        // // ends with 'ы' or 'и': plural form
44
        // if (in_array(S::slice($name, -1), array('и', 'ы')))
45
        //     return false;
46
47 2
        if (in_array($name, self::$abbreviations, true) || in_array($name, self::$immutableParts, true)) {
48 2
            return false;
49
        }
50
51
        if (strpos($name, ' ') !== false) {
52
            list($first_part, $last_part) = explode(' ', $name, 2);
53
54
            // город N, село N, хутор N, район N, поселок N, округ N, республика N
55
            // N область, N край
56
            if (in_array($first_part, ['город', 'село', 'хутор', 'район', 'поселок', 'округ', 'республика'], true)
57
                || in_array($last_part, ['край', 'область'], true)) {
58
                return true;
59
            }
60
61
            // пгт N
62
            if ($first_part === 'пгт')
63
                return false;
64
        }
65
66
        // ends with 'е' or 'о', but not with 'ово/ёво/ево/ино/ыно'
67
        if (in_array(S::slice($name, -1), ['е', 'о'], true) && !in_array(S::slice($name, -3, -1), ['ов', 'ёв', 'ев', 'ин', 'ын'], true)) {
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 41 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
68
            return false;
69
        }
70
        return true;
71
    }
72
73
    /**
74
     * Получение всех форм названия
75
     * @param string $name
76
     * @return array
77
     * @throws \Exception
78
     */
79 33
    public static function getCases($name)
80
    {
81 33
        $name = S::lower($name);
82
83 33
        if (in_array($name, self::$immutableParts, true)) {
84 1
            return array_fill_keys([self::IMENIT, self::RODIT, self::DAT, self::VINIT, self::TVORIT, self::PREDLOJ], S::name($name));
85
        }
86
87 33
        if (strpos($name, ' ') !== false) {
88 8
            $first_part = S::slice($name, 0, S::findFirstPosition($name, ' '));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::findFirstPosition() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
89
            // город N, село N, хутор N, пгт N
90 8
            if (in_array($first_part, ['город', 'село', 'хутор', 'пгт', 'район', 'поселок', 'округ', 'республика'], true)) {
91 3
                if ($first_part !== 'пгт')
92 3
                    return self::composeCasesFromWords([
93 3
                        NounDeclension::getCases($first_part),
94 3
                        array_fill_keys(self::getAllCases(), S::name(S::slice($name, S::length($first_part) + 1)))
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
95
                    ]);
96
                else
97
                    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
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
98
            }
99
100 5
            $last_part = S::slice($name,
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
101 5
                S::findLastPosition($name, ' ') + 1);
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::findLastPosition() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
102
            // N область, N край
103 5
            if (in_array($last_part, ['край', 'область'], true)) {
104 2
                return self::composeCasesFromWords([static::getCases(S::slice($name, 0, S::findLastPosition($name, ' '))), NounDeclension::getCases($last_part)]);
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::findLastPosition() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
Security Bug introduced by wapmorgan
It seems like \morphos\S::slice($name,...stPosition($name, ' ')) targeting morphos\S::slice() can also be of type false; however, morphos\Russian\Geograph...sInflection::getCases() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
105
            }
106
        }
107
108
        // Сложное название через пробел, '-' или '-на-'
109 30
        foreach (self::$delimiters as $delimiter) {
110 30
            if (strpos($name, $delimiter) !== false) {
111 5
                $parts = explode($delimiter, $name);
112 5
                $result = [];
113 5
                foreach ($parts as $i => $part) {
114 5
                    $result[$i] = static::getCases($part);
115
                }
116 30
                return self::composeCasesFromWords($result, $delimiter);
117
            }
118
        }
119
120 30
        if (!in_array($name, self::$abbreviations, true)) {
121 28
            switch (S::slice($name, -2)) {
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
122
                // Нижний, Русский
123 28
                case 'ий':
124 2
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
125
                    return [
126 2
                        self::IMENIT => $prefix . 'ий',
127 2
                        self::RODIT => $prefix . (self::isVelarConsonant(S::slice($name, -3, -2)) ? 'ого' : 'его'),
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
128 2
                        self::DAT => $prefix . (self::isVelarConsonant(S::slice($name, -3, -2)) ? 'ому' : 'ему'),
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
129 2
                        self::VINIT => $prefix . 'ий',
130 2
                        self::TVORIT => $prefix . 'им',
131 2
                        self::PREDLOJ => $prefix . (self::chooseEndingBySonority($prefix, 'ем', 'ом')),
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $prefix defined by \morphos\S::name(\morphos\S::slice($name, 0, -2)) on line 124 can also be of type false; however, morphos\Russian\RussianL...hooseEndingBySonority() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
132
                    ];
133
134
                // Ростовская
135 27
                case 'ая':
136 1
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
137
                    return [
138 1
                        self::IMENIT => $prefix . 'ая',
139 1
                        self::RODIT => $prefix . 'ой',
140 1
                        self::DAT => $prefix . 'ой',
141 1
                        self::VINIT => $prefix . 'ую',
142 1
                        self::TVORIT => $prefix . 'ой',
143 1
                        self::PREDLOJ => $prefix . 'ой',
144
                    ];
145
146
                // Грозный, Благодарный
147 26
                case 'ый':
148 2
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
149
                    return [
150 2
                        self::IMENIT => $prefix . 'ый',
151 2
                        self::RODIT => $prefix . 'ого',
152 2
                        self::DAT => $prefix . 'ому',
153 2
                        self::VINIT => $prefix . 'ый',
154 2
                        self::TVORIT => $prefix . 'ым',
155 2
                        self::PREDLOJ => $prefix . 'ом',
156
                    ];
157
158
                // Ставрополь, Ярославль
159 24
                case 'ль':
160 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
161
                    return [
162 1
                        self::IMENIT => $prefix . 'ь',
163 1
                        self::RODIT => $prefix . 'я',
164 1
                        self::DAT => $prefix . 'ю',
165 1
                        self::VINIT => $prefix . 'ь',
166 1
                        self::TVORIT => $prefix . 'ем',
167 1
                        self::PREDLOJ => $prefix . 'е',
168
                    ];
169
170
                // Тверь, Анадырь
171 23
                case 'рь':
172 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
173 2
                    $last_vowel = S::slice($prefix, -2, -1);
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $prefix defined by \morphos\S::name(\morphos\S::slice($name, 0, -1)) on line 172 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
174
                    return [
175 2
                        self::IMENIT => $prefix . 'ь',
176 2
                        self::RODIT => $prefix . (self::isBinaryVowel($last_vowel) ? 'и' : 'я'),
177 2
                        self::DAT => $prefix . (self::isBinaryVowel($last_vowel) ? 'и' : 'ю'),
178 2
                        self::VINIT => $prefix . 'ь',
179 2
                        self::TVORIT => $prefix . (self::isBinaryVowel($last_vowel) ? 'ью' : 'ем'),
180 2
                        self::PREDLOJ => $prefix . (self::isBinaryVowel($last_vowel) ? 'и' : 'е'),
181
                    ];
182
183
                // Березники, Ессентуки
184 21
                case 'ки':
185 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
186
                    return [
187 2
                        self::IMENIT => $prefix . 'и',
188 2
                        self::RODIT => $name == 'луки' ? $prefix : $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 20
                case 'мь':
197 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
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
                // Рязань, Назрань
208 19
                case 'нь':
209 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
210
                    return [
211 1
                        self::IMENIT => $prefix . 'ь',
212 1
                        self::RODIT => $prefix . 'и',
213 1
                        self::DAT => $prefix . 'и',
214 1
                        self::VINIT => $prefix . 'ь',
215 1
                        self::TVORIT => $prefix . 'ью',
216 1
                        self::PREDLOJ => $prefix . 'и',
217
                    ];
218
219
                // Набережные
220 18
                case 'ые':
221 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
222
                    return [
223 1
                        self::IMENIT => $prefix . 'е',
224 1
                        self::RODIT => $prefix . 'х',
225 1
                        self::DAT => $prefix . 'м',
226 1
                        self::VINIT => $prefix . 'е',
227 1
                        self::TVORIT => $prefix . 'ми',
228 1
                        self::PREDLOJ => $prefix . 'х',
229
                    ];
230
231
                // Челны
232 18
                case 'ны':
233 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
234
                    return [
235 1
                        self::IMENIT => $prefix . 'ы',
236 1
                        self::RODIT => $prefix . 'ов',
237 1
                        self::DAT => $prefix . 'ам',
238 1
                        self::VINIT => $prefix . 'ы',
239 1
                        self::TVORIT => $prefix . 'ами',
240 1
                        self::PREDLOJ => $prefix . 'ах',
241
                    ];
242
243
                // Великие
244 17
                case 'ие':
245 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
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 16
                case 'чь':
257 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
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
269 15
            switch (S::slice($name, -1)) {
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
270
                // Азия
271 15
                case 'я':
272 1
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
273
                    return [
274 1
                        self::IMENIT => S::name($name),
275 1
                        self::RODIT => $prefix.'и',
276 1
                        self::DAT => $prefix.'и',
277 1
                        self::VINIT => $prefix.'ю',
278 1
                        self::TVORIT => $prefix.'ей',
279 1
                        self::PREDLOJ => $prefix.'и',
280
                    ];
281
282 14 View Code Duplication
                case 'а':
0 ignored issues
show
Duplication introduced by wapmorgan
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
283
                    // Москва, Рига
284 5
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
285
                    return [
286 5
                        self::IMENIT => $prefix.'а',
287 5
                        self::RODIT => $prefix.(self::isVelarConsonant(S::slice($name, -2, -1)) ? 'и' : 'ы'),
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
288 5
                        self::DAT => $prefix.'е',
289 5
                        self::VINIT => $prefix.'у',
290 5
                        self::TVORIT => $prefix.'ой',
291 5
                        self::PREDLOJ => $prefix.'е',
292
                    ];
293
294 9
                case 'й':
295
                    // Ишимбай
296 2
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
297
                    return [
298 2
                        self::IMENIT => $prefix . 'й',
299 2
                        self::RODIT => $prefix . 'я',
300 2
                        self::DAT => $prefix . 'ю',
301 2
                        self::VINIT => $prefix . 'й',
302 2
                        self::TVORIT => $prefix . 'ем',
303 2
                        self::PREDLOJ => $prefix . 'е',
304
                    ];
305
            }
306
307 7
            if (self::isConsonant(S::slice($name,  -1)) && !in_array($name, self::$ovAbnormalExceptions, true)) {
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
308
                // Париж, Валаам, Киев
309 6
                $prefix = S::name($name);
310
                return [
311 6
                    self::IMENIT => $prefix,
312 6
                    self::RODIT => $prefix . 'а',
313 6
                    self::DAT => $prefix . 'у',
314 6
                    self::VINIT => $prefix,
315 6
                    self::TVORIT => $prefix . (self::isVelarConsonant(S::slice($name, -2, -1)) ? 'ем' : 'ом'),
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
316 6
                    self::PREDLOJ => $prefix . 'е',
317
                ];
318
            }
319
320
            // ов, ово, ёв, ёво, ев, ево, ...
321 2
            $suffixes = ['ов', 'ёв', 'ев', 'ин', 'ын'];
322 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
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
323
                // ово, ёво, ...
324 1
                if (in_array(S::slice($name, -3, -1), $suffixes, true)) {
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
325
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
326
                }
327
                // ов, её, ...
328 1
                elseif (in_array(S::slice($name, -2), $suffixes, true)) {
0 ignored issues
show
Security Bug introduced by wapmorgan
It seems like $name defined by \morphos\S::lower($name) on line 81 can also be of type false; however, morphos\S::slice() does only seem to accept string, did you maybe forget to handle an error condition?

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

Consider the follow example

<?php

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

    return false;
}

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

Loading history...
329 1
                    $prefix = S::name($name);
330
                }
331
                return [
332 1
                    self::IMENIT => S::name($name),
333 1
                    self::RODIT => $prefix.'а',
334 1
                    self::DAT => $prefix.'у',
335 1
                    self::VINIT => S::name($name),
336 1
                    self::TVORIT => $prefix.'ым',
337 1
                    self::PREDLOJ => $prefix.'е',
338
                ];
339
            }
340
        }
341
342
        // if no rules matches or name is immutable
343 3
        $name = in_array($name, self::$abbreviations, true) ? S::upper($name) : S::name($name);
344 3
        return array_fill_keys([self::IMENIT, self::RODIT, self::DAT, self::VINIT, self::TVORIT, self::PREDLOJ], $name);
345
    }
346
347
    /**
348
     * Получение одной формы (падежа) названия.
349
     * @param string $name  Название
350
     * @param integer $case Падеж. Одна из констант \morphos\Russian\Cases или \morphos\Cases.
351
     * @see \morphos\Russian\Cases
352
     * @return string
353
     * @throws \Exception
354
     */
355
    public static function getCase($name, $case)
356
    {
357
        $case = self::canonizeCase($case);
358
        $forms = self::getCases($name);
359
        return $forms[$case];
360
    }
361
}
362