Completed
Pull Request — master (#66)
by
unknown
01:32
created

LastNamesInflection   A

Complexity

Total Complexity 37

Size/Duplication

Total Lines 240
Duplicated Lines 22.08 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
dl 53
loc 240
ccs 120
cts 126
cp 0.9524
rs 9.44
c 0
b 0
f 0
wmc 37
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
C isMutable() 15 57 14
A detectGender() 0 12 3
F getCases() 38 129 18
A getCase() 0 10 2

How to fix   Duplicated Code   

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:

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

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
31 3
                    return true;
32
            }
33
            return false;
34
        }
35
36 60 View Code Duplication
        if (in_array(S::slice($name, -1), ['а', 'я'], true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
37 22
            return true;
38
        }
39
        
40
        // Несклоняемые фамилии независимо от пола (Токаревских)
41 39 View Code Duplication
        if (in_array(S::slice($name, -2), ['их'], true))
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
42
            return false;
43
44 39
        if ($gender == static::MALE) {
45
            // Несклоняемые фамилии (Фоминых, Седых / Стецко, Писаренко)
46 38 View Code Duplication
            if (in_array(S::slice($name, -2), ['ых', 'ко'], true))
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
47 1
                return false;
48
49
            // Несклоняемые, образованные из родительного падежа личного или прозвищного имени главы семьи
50
            // суффиксы: ово, аго
51 37 View Code Duplication
            if (in_array(S::slice($name, -3), ['ово', 'аго'], true))
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
52 1
                return false;
53
54
            // Типичные суффикс мужских фамилий
55 36
            if (in_array(S::slice($name, -2), ['ов', 'ев', 'ин', 'ын', 'ий', 'ой'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56 13
                return true;
57
            }
58
59
            // Согласная на конце
60 23
            if (static::isConsonant(S::slice($name, -1))) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61 15
                return true;
62
            }
63
64
            // Мягкий знак на конце
65 8
            if (S::slice($name, -1) == 'ь') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
66 8
                return true;
67
            }
68
69 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
70
            // Типичные суффиксы женских фамилий
71 1
            if (in_array(S::slice($name, -2), ['ва', 'на', 'ая'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 23 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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

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

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

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

Loading history...
112 3
            foreach ($parts as $i => $part) {
113 3
                $parts[$i] = static::getCases($part, $gender);
114
            }
115
116 3
            return static::composeCasesFromWords($parts, '-');
117
        }
118
119 36
        if (static::isMutable($name, $gender)) {
0 ignored issues
show
Bug introduced by
It seems like $gender can also be of type string; however, morphos\Russian\LastNamesInflection::isMutable() does only seem to accept null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
120 35
            if ($gender == static::MALE) {
121 22
                if (in_array(S::slice($name, -2), ['ов', 'ев', 'ин', 'ын'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
122 5
                    $prefix = S::name($name);
123
                    return [
124 5
                        static::IMENIT => $prefix,
125 5
                        static::RODIT => $prefix.'а',
126 5
                        static::DAT => $prefix.'у',
127 5
                        static::VINIT => $prefix.'а',
128 5
                        static::TVORIT => $prefix.'ым',
129 5
                        static::PREDLOJ => $prefix.'е'
130
                    ];
131 17 View Code Duplication
                } elseif (in_array(S::slice($name, -4), ['ский', 'ской', 'цкий', 'цкой'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
132 1
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
133
                    return [
134 1
                        static::IMENIT => S::name($name),
135 1
                        static::RODIT => $prefix.'ого',
136 1
                        static::DAT => $prefix.'ому',
137 1
                        static::VINIT => $prefix.'ого',
138 1
                        static::TVORIT => $prefix.'им',
139 1
                        static::PREDLOJ => $prefix.'ом'
140
                    ];
141
                // Верхний / Убогий / Толстой
142
                // Верхнего / Убогого / Толстого
143
                // Верхнему / Убогому / Толстому
144
                // Верхним / Убогим / Толстым
145
                // О Верхнем / Об Убогом / О Толстом
146 16
                } else if (in_array(S::slice($name, -2), ['ой', 'ый', 'ий'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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 3
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
148
                    return [
149 3
                        static::IMENIT => S::name($name),
150 3
                        static::RODIT => $prefix.'ого',
151 3
                        static::DAT => $prefix.'ому',
152 3
                        static::VINIT => $prefix.'ого',
153 3
                        static::TVORIT => $prefix.'ым',
154 16
                        static::PREDLOJ => $prefix.'ом'
155
                    ];
156
                }
157
158
            } else {
159 13 View Code Duplication
                if (in_array(S::slice($name, -3), ['ова', 'ева', 'ина', 'ына'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
160 5
                    $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
161
                    return [
162 5
                        static::IMENIT => S::name($name),
163 5
                        static::RODIT => $prefix.'ой',
164 5
                        static::DAT => $prefix.'ой',
165 5
                        static::VINIT => $prefix.'у',
166 5
                        static::TVORIT => $prefix.'ой',
167 5
                        static::PREDLOJ => $prefix.'ой'
168
                    ];
169
                }
170
171 8
                if (in_array(S::slice($name, -2), ['ая'], true)) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
172 3
                    $prefix = S::name(S::slice($name, 0, -2));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
173
                    return [
174 3
                        static::IMENIT => S::name($name),
175 3
                        static::RODIT => $prefix.'ой',
176 3
                        static::DAT => $prefix.'ой',
177 3
                        static::VINIT => $prefix.'ую',
178 3
                        static::TVORIT => $prefix.'ой',
179 3
                        static::PREDLOJ => $prefix.'ой'
180
                    ];
181
                }
182
            }
183
184 18
            if (S::slice($name, -1) == 'я') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
185 1
                $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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 1
                    static::IMENIT => S::name($name),
188 1
                    static::RODIT => $prefix.'и',
189 1
                    static::DAT => $prefix.'е',
190 1
                    static::VINIT => $prefix.'ю',
191 1
                    static::TVORIT => $prefix.'ей',
192 1
                    static::PREDLOJ => $prefix.'е'
193
                ];
194 17 View Code Duplication
            } elseif (S::slice($name, -1) == 'а') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
195 5
                $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 can also be of type boolean; however, morphos\S::slice() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
196
                return [
197 5
                    static::IMENIT => S::name($name),
198 5
                    static::RODIT => $prefix.(static::isDeafConsonant(S::slice($name, -2, -1)) ? 'и' : 'ы'),
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
199 5
                    static::DAT => $prefix.'е',
200 5
                    static::VINIT => $prefix.'у',
201 5
                    static::TVORIT => $prefix.'ой',
202 5
                    static::PREDLOJ => $prefix.'е'
203
                ];
204 12
            } elseif (static::isConsonant(S::slice($name, -1)) && S::slice($name, -2) != 'ых') {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
205 9
                $prefix = S::name($name);
206
                return [
207 9
                    static::IMENIT => S::name($name),
208 9
                    static::RODIT => $prefix.'а',
209 9
                    static::DAT => $prefix.'у',
210 9
                    static::VINIT => $prefix.'а',
211 9
                    static::TVORIT => $prefix.'ом',
212 9
                    static::PREDLOJ => $prefix.'е'
213
                ];
214 3
            } elseif (S::slice($name, -1) == 'ь' && $gender == static::MALE) {
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
215 3
                $prefix = S::name(S::slice($name, 0, -1));
0 ignored issues
show
Bug introduced by
It seems like $name defined by \morphos\S::lower($name) on line 103 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...
216
                return [
217 3
                    static::IMENIT => S::name($name),
218 3
                    static::RODIT => $prefix.'я',
219 3
                    static::DAT => $prefix.'ю',
220 3
                    static::VINIT => $prefix.'я',
221 3
                    static::TVORIT => $prefix.'ем',
222 3
                    static::PREDLOJ => $prefix.'е'
223
                ];
224
            }
225
        }
226
227 2
        $name = S::name($name);
228 2
        return array_fill_keys([static::IMENIT, static::RODIT, static::DAT, static::VINIT, static::TVORIT, static::PREDLOJ], $name);
229
    }
230
231
    /**
232
     * @param $name
233
     * @param $case
234
     * @param null $gender
235
     * @return string
236
     * @throws \Exception
237
     */
238 6
    public static function getCase($name, $case, $gender = null)
239
    {
240 6
        if (!static::isMutable($name, $gender)) {
241
            return $name;
242
        } else {
243 6
            $case = static::canonizeCase($case);
244 6
            $forms = static::getCases($name, $gender);
245 6
            return $forms[$case];
246
        }
247
    }
248
}
249