Conditions | 35 |
Paths | 1008 |
Total Lines | 81 |
Code Lines | 56 |
Lines | 12 |
Ratio | 14.81 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
114 | protected static function declinateSubstative($word, $animateness) |
||
115 | { |
||
116 | $prefix = S::slice($word, 0, -1); |
||
117 | $last = S::slice($word, -1); |
||
118 | |||
119 | $runaway_vowels_list = static::getRunAwayVowelsList(); |
||
120 | if (isset($runaway_vowels_list[$word])) { |
||
121 | $vowel_offset = $runaway_vowels_list[$word]; |
||
122 | $word = S::slice($word, 0, $vowel_offset) . S::slice($word, $vowel_offset + 1); |
||
123 | } |
||
124 | |||
125 | if (($declension = NounDeclension::getDeclension($word)) == NounDeclension::SECOND_DECLENSION) { |
||
126 | $soft_last = $last == 'й' || (in_array($last, ['ь', 'е', 'ё', 'ю', 'я']) && ((self::isConsonant(S::slice($word, -2, -1)) && !self::isHissingConsonant(S::slice($word, -2, -1))) || S::slice($word, -2, -1) == 'и')); |
||
127 | $prefix = NounDeclension::getPrefixOfSecondDeclension($word, $last); |
||
128 | } elseif ($declension == NounDeclension::FIRST_DECLENSION) { |
||
129 | $soft_last = self::checkLastConsonantSoftness($word); |
||
130 | } else { |
||
131 | $soft_last = S::slice($word, -2) == 'сь'; |
||
132 | } |
||
133 | |||
134 | $forms = array(); |
||
135 | |||
136 | if ($last == 'ч' || in_array(S::slice($word, -2), array('чь', 'сь')) || (self::isVowel($last) && in_array(S::slice($word, -2, -1), array('ч', 'к')))) { // before ч, чь, сь, ч+vowel, к+vowel |
||
137 | $forms[Cases::IMENIT] = $prefix.'и'; |
||
138 | } elseif ($last == 'н' || $last == 'ц') { |
||
139 | $forms[Cases::IMENIT] = $prefix.'ы'; |
||
140 | View Code Duplication | } else { |
|
141 | $forms[Cases::IMENIT] = self::chooseVowelAfterConsonant($last, $soft_last, $prefix.'я', $prefix.'а'); |
||
142 | } |
||
143 | |||
144 | // RODIT |
||
145 | if (isset(self::$genitiveExceptions[$word])) { |
||
146 | $forms[Cases::RODIT] = self::$genitiveExceptions[$word]; |
||
147 | } elseif (in_array($last, array('о', 'е'))) { |
||
148 | // exceptions |
||
149 | if (in_array($word, self::$neuterExceptions)) { |
||
150 | $forms[Cases::RODIT] = $prefix.'ей'; |
||
151 | View Code Duplication | } elseif (S::slice($word, -2, -1) == 'и') { |
|
152 | $forms[Cases::RODIT] = $prefix.'й'; |
||
153 | } else { |
||
154 | $forms[Cases::RODIT] = $prefix; |
||
155 | } |
||
156 | } elseif (S::slice($word, -2) == 'ка') { // words ending with -ка: чашка, вилка, ложка, тарелка, копейка, батарейка |
||
157 | if (S::slice($word, -3, -2) == 'л') { |
||
158 | $forms[Cases::RODIT] = S::slice($word, 0, -2).'ок'; |
||
159 | View Code Duplication | } elseif (S::slice($word, -3, -2) == 'й') { |
|
160 | $forms[Cases::RODIT] = S::slice($word, 0, -3).'ек'; |
||
161 | } else { |
||
162 | $forms[Cases::RODIT] = S::slice($word, 0, -2).'ек'; |
||
163 | } |
||
164 | } elseif (in_array($last, array('а'))) { // обида, ябеда |
||
165 | $forms[Cases::RODIT] = $prefix; |
||
166 | } elseif (in_array($last, array('я'))) { // молния |
||
167 | $forms[Cases::RODIT] = $prefix.'й'; |
||
168 | } elseif (RussianLanguage::isHissingConsonant($last) || ($soft_last && $last != 'й') || in_array(S::slice($word, -2), array('чь', 'сь'))) { |
||
169 | $forms[Cases::RODIT] = $prefix.'ей'; |
||
170 | View Code Duplication | } elseif ($last == 'й' || S::slice($word, -2) == 'яц') { // месяц |
|
171 | $forms[Cases::RODIT] = $prefix.'ев'; |
||
172 | } else { // (self::isConsonant($last) && !RussianLanguage::isHissingConsonant($last)) |
||
173 | $forms[Cases::RODIT] = $prefix.'ов'; |
||
174 | } |
||
175 | |||
176 | // DAT |
||
177 | $forms[Cases::DAT] = self::chooseVowelAfterConsonant($last, $soft_last && S::slice($word, -2, -1) != 'ч', $prefix.'ям', $prefix.'ам'); |
||
178 | |||
179 | // VINIT |
||
180 | $forms[Cases::VINIT] = NounDeclension::getVinitCaseByAnimateness($forms, $animateness); |
||
181 | |||
182 | // TVORIT |
||
183 | // my personal rule |
||
184 | if ($last == 'ь' && $declension == NounDeclension::THIRD_DECLENSION && !in_array(S::slice($word, -2), array('чь', 'сь'))) { |
||
185 | $forms[Cases::TVORIT] = $prefix.'ми'; |
||
186 | } else { |
||
187 | $forms[Cases::TVORIT] = self::chooseVowelAfterConsonant($last, $soft_last && S::slice($word, -2, -1) != 'ч', $prefix.'ями', $prefix.'ами'); |
||
188 | } |
||
189 | |||
190 | // PREDLOJ |
||
191 | $forms[Cases::PREDLOJ] = self::chooseVowelAfterConsonant($last, $soft_last && S::slice($word, -2, -1) != 'ч', $prefix.'ях', $prefix.'ах'); |
||
192 | $forms[Cases::PREDLOJ] = self::choosePrepositionByFirstLetter($forms[Cases::PREDLOJ], 'об', 'о').' '.$forms[Cases::PREDLOJ]; |
||
193 | return $forms; |
||
194 | } |
||
195 | |||
213 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..