This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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\Gender; |
||
5 | use morphos\S; |
||
6 | |||
7 | /** |
||
8 | * Inflects the name in one case. |
||
9 | * @param string $fullName Name in "F", "L F" or "L M F" format, where L - last name, M - middle name, F - first name |
||
10 | * @param string $case Case to inflect to. |
||
11 | * Should be one of [[morphos\Cases]] or [[morphos\Russian\Cases]] constants. |
||
12 | * @param null|string $gender Gender of name owner. If null, auto detection will be used. |
||
13 | * Should be one of [[morphos\Gender]] constants. |
||
14 | * @return string|false Returns string containing the inflection of name to a case. |
||
15 | * @throws \Exception |
||
16 | */ |
||
17 | function inflectName($fullName, $case = null, $gender = null) |
||
18 | { |
||
19 | 18 | if (in_array($case, [Gender::MALE, Gender::FEMALE, null], true)) { |
|
20 | 10 | return $case === null ? getNameCases($fullName) : getNameCases($fullName, $case); |
|
21 | } |
||
22 | |||
23 | 8 | $fullName = normalizeFullName($fullName); |
|
24 | 8 | $case = CasesHelper::canonizeCase($case); |
|
25 | 8 | if ($gender === null) $gender = detectGender($fullName); |
|
26 | |||
27 | 8 | $name = explode(' ', $fullName); |
|
28 | |||
29 | 8 | switch (count($name)) { |
|
30 | 8 | case 1: |
|
31 | 1 | $name[0] = FirstNamesInflection::getCase($name[0], $case, $gender); |
|
32 | 1 | break; |
|
33 | |||
34 | 7 | View Code Duplication | case 2: |
0 ignored issues
–
show
|
|||
35 | 1 | $name[0] = LastNamesInflection::getCase($name[0], $case, $gender); |
|
36 | 1 | $name[1] = FirstNamesInflection::getCase($name[1], $case, $gender); |
|
37 | 1 | break; |
|
38 | |||
39 | 6 | View Code Duplication | case 3: |
0 ignored issues
–
show
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...
|
|||
40 | 5 | $name[0] = LastNamesInflection::getCase($name[0], $case, $gender); |
|
41 | 5 | $name[1] = FirstNamesInflection::getCase($name[1], $case, $gender); |
|
42 | 5 | $name[2] = MiddleNamesInflection::getCase($name[2], $case, $gender); |
|
43 | 5 | break; |
|
44 | |||
45 | default: |
||
46 | 1 | return false; |
|
47 | } |
||
48 | |||
49 | 7 | return implode(' ', $name); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Inflects the name to all cases. |
||
54 | * @param string $fullName Name in "F", "L F" or "L M F" format, where L - last name, M - middle name, F - first name |
||
55 | * @param null|string $gender Gender of name owner. If null, auto detection will be used. |
||
56 | * Should be one of [[morphos\Gender]] constants. |
||
57 | * @return string[]|false Returns an array with name inflected to all cases. |
||
58 | */ |
||
59 | function getNameCases($fullName, $gender = null) |
||
60 | { |
||
61 | 11 | $fullName = normalizeFullName($fullName); |
|
62 | 11 | if ($gender === null) $gender = detectGender($fullName); |
|
63 | |||
64 | 11 | $name = explode(' ', $fullName); |
|
65 | |||
66 | 11 | switch (count($name)) { |
|
67 | 11 | case 1: |
|
68 | 1 | $name[0] = FirstNamesInflection::getCases($name[0], $gender); |
|
69 | 1 | break; |
|
70 | |||
71 | 10 | View Code Duplication | case 2: |
0 ignored issues
–
show
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...
|
|||
72 | 1 | $name[0] = LastNamesInflection::getCases($name[0], $gender); |
|
73 | 1 | $name[1] = FirstNamesInflection::getCases($name[1], $gender); |
|
74 | 1 | break; |
|
75 | |||
76 | 9 | View Code Duplication | case 3: |
0 ignored issues
–
show
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...
|
|||
77 | 8 | $name[0] = LastNamesInflection::getCases($name[0], $gender); |
|
78 | 8 | $name[1] = FirstNamesInflection::getCases($name[1], $gender); |
|
79 | 8 | $name[2] = MiddleNamesInflection::getCases($name[2], $gender); |
|
80 | 8 | break; |
|
81 | |||
82 | default: |
||
83 | 1 | return false; |
|
84 | } |
||
85 | |||
86 | 10 | return CasesHelper::composeCasesFromWords($name); |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * Guesses the gender of name owner. |
||
91 | * @param string $fullName Name in "F", "L F" or "L M F" format, where L - last name, M - middle name, F - first name |
||
92 | * @return null|string Null if not detected. One of [[morphos\Gender]] constants. |
||
93 | */ |
||
94 | function detectGender($fullName) |
||
95 | { |
||
96 | 2 | $gender = null; |
|
97 | 2 | $name = explode(' ', S::lower($fullName)); |
|
98 | 2 | $nameCount = count($name); |
|
99 | 2 | if ($nameCount > 3) { |
|
100 | 1 | return null; |
|
101 | } |
||
102 | |||
103 | 1 | if ($nameCount === 1) |
|
104 | 1 | return FirstNamesInflection::detectGender($name[0]); |
|
105 | 1 | else if ($nameCount === 2) |
|
106 | 1 | return LastNamesInflection::detectGender($name[0]) |
|
107 | 1 | ?: FirstNamesInflection::detectGender($name[1]); |
|
108 | else |
||
109 | 1 | return MiddleNamesInflection::detectGender($name[2]) |
|
110 | ?: (LastNamesInflection::detectGender($name[0]) |
||
111 | 1 | ?: FirstNamesInflection::detectGender($name[1])); |
|
112 | } |
||
113 | |||
114 | /** |
||
115 | * Normalizes a full name. Swaps name parts to make "L F" or "L M F" scheme. |
||
116 | * @param string $name Input name |
||
117 | * @return string Normalized name |
||
118 | */ |
||
119 | function normalizeFullName($name) |
||
120 | { |
||
121 | 18 | $name = preg_replace('~[ ]{2,}~', '', trim($name)); |
|
122 | 18 | return $name; |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * Генерация строки с числом и существительным, в правильной форме для сочетания с числом (кол-вом предметов). |
||
127 | * |
||
128 | * @param int $count Количество предметов |
||
129 | * @param string $word Название предмета ИЛИ "прилагатально предмет". Может включать в себя несколько |
||
130 | * прилагательных перед существительным. |
||
131 | * Например: "сообщение", "новое сообщение", "небольшая лампа". |
||
132 | * @param bool $animateness Признак одушевленности |
||
133 | * @param string $case Род существительного (по умолчанию именительный для 1 предмета и родительный для |
||
134 | * нескольких) |
||
135 | * |
||
136 | * @return string Строка в формате "ЧИСЛО [СУЩ в правильной форме]" |
||
137 | * @throws \Exception |
||
138 | */ |
||
139 | function pluralize($count, $word, $animateness = false, $case = null) |
||
140 | { |
||
141 | // меняем местами аргументы, если они переданы в старом формате |
||
142 | // @phpstan-ignore-next-line |
||
143 | 18 | View Code Duplication | if (is_string($count) && is_numeric($word)) { |
0 ignored issues
–
show
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...
|
|||
144 | 1 | list($count, $word) = [$word, $count]; |
|
145 | } |
||
146 | |||
147 | 18 | if (strpos($word, ' ') !== false) { |
|
148 | 1 | $words = explode(' ', $word); |
|
149 | 1 | $noun = array_pop($words); |
|
150 | |||
151 | 1 | foreach ($words as $i => $word) { |
|
152 | 1 | if (in_array($word, RussianLanguage::$unions, true)) |
|
153 | $words[$i] = $word; |
||
154 | else |
||
155 | 1 | $words[$i] = AdjectivePluralization::pluralize($word, $count, $animateness, $case); |
|
156 | } |
||
157 | |||
158 | 1 | return $count.' '.implode(' ', $words).' '.NounPluralization::pluralize($count, $noun, $animateness, $case); |
|
159 | } |
||
160 | |||
161 | 18 | return $count.' '.NounPluralization::pluralize($word, $count, $animateness, $case); |
|
162 | } |
||
163 |
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.