Conditions | 33 |
Paths | 864 |
Total Lines | 75 |
Code Lines | 53 |
Lines | 12 |
Ratio | 16 % |
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 |
||
97 | static protected function declinateSubstative($word, $animateness) { |
||
98 | $prefix = S::slice($word, 0, -1); |
||
99 | $last = S::slice($word, -1); |
||
100 | |||
101 | $runaway_vowels_list = static::getRunAwayVowelsList(); |
||
102 | if (isset($runaway_vowels_list[$word])) { |
||
103 | $vowel_offset = $runaway_vowels_list[$word]; |
||
104 | $word = S::slice($word, 0, $vowel_offset) . S::slice($word, $vowel_offset + 1); |
||
105 | } |
||
106 | |||
107 | if (($declension = GeneralDeclension::getDeclension($word)) == GeneralDeclension::SECOND_DECLENSION) { |
||
108 | $soft_last = $last == 'й' || (in_array($last, ['ь', 'е', 'ё', 'ю', 'я']) && (self::isConsonant(S::slice($word, -2, -1)) || S::slice($word, -2, -1) == 'и')); |
||
109 | $prefix = GeneralDeclension::getPrefixOfSecondDeclension($word, $last); |
||
110 | } else if ($declension == GeneralDeclension::FIRST_DECLENSION) { |
||
111 | $soft_last = self::checkLastConsonantSoftness($word); |
||
112 | } else { |
||
113 | $soft_last = S::slice($word, -2) == 'сь'; |
||
114 | } |
||
115 | |||
116 | $forms = array(); |
||
117 | |||
118 | if ($last == 'ч' || in_array(S::slice($word, -2), array('чь', 'сь')) || (self::isVowel($last) && in_array(S::slice($word, -2, -1), array('ч', 'к')))) // before ч, чь, сь, ч+vowel, к+vowel |
||
119 | $forms[Cases::IMENIT] = $prefix.'и'; |
||
120 | View Code Duplication | else if ($last == 'н' || $last == 'ц') |
|
121 | $forms[Cases::IMENIT] = $prefix.'ы'; |
||
122 | else |
||
123 | $forms[Cases::IMENIT] = self::chooseVowelAfterConsonant($last, $soft_last, $prefix.'я', $prefix.'а'); |
||
124 | |||
125 | // RODIT |
||
126 | if ($word == 'письмо') |
||
127 | $forms[Cases::RODIT] = 'писем'; |
||
128 | else if (in_array($last, array('о', 'е'))) { |
||
129 | // exceptions |
||
130 | if (in_array($word, self::$neuterExceptions)) |
||
131 | $forms[Cases::RODIT] = $prefix.'ей'; |
||
132 | View Code Duplication | else if (S::slice($word, -2, -1) == 'и') |
|
133 | $forms[Cases::RODIT] = $prefix.'й'; |
||
134 | else |
||
135 | $forms[Cases::RODIT] = $prefix; |
||
136 | } |
||
137 | else if (S::slice($word, -2) == 'ка') { // words ending with -ка: чашка, вилка, ложка, тарелка, копейка, батарейка |
||
138 | if (S::slice($word, -3, -2) == 'л') $forms[Cases::RODIT] = S::slice($word, 0, -2).'ок'; |
||
139 | else if (S::slice($word, -3, -2) == 'й') $forms[Cases::RODIT] = S::slice($word, 0, -3).'ек'; |
||
140 | else $forms[Cases::RODIT] = S::slice($word, 0, -2).'ек'; |
||
141 | } |
||
142 | else if (in_array($last, array('а'))) // обида, ябеда |
||
143 | $forms[Cases::RODIT] = $prefix; |
||
144 | else if (in_array($last, array('я'))) // молния |
||
145 | $forms[Cases::RODIT] = $prefix.'й'; |
||
146 | else if (RussianLanguage::isHissingConsonant($last) || ($soft_last && $last != 'й') || in_array(S::slice($word, -2), array('чь', 'сь'))) |
||
147 | $forms[Cases::RODIT] = $prefix.'ей'; |
||
148 | View Code Duplication | else if ($last == 'й') |
|
149 | $forms[Cases::RODIT] = $prefix.'ев'; |
||
150 | else // (self::isConsonant($last) && !RussianLanguage::isHissingConsonant($last)) |
||
151 | $forms[Cases::RODIT] = $prefix.'ов'; |
||
152 | |||
153 | // DAT |
||
154 | $forms[Cases::DAT] = self::chooseVowelAfterConsonant($last, $soft_last && S::slice($word, -2, -1) != 'ч', $prefix.'ям', $prefix.'ам'); |
||
155 | |||
156 | // VINIT |
||
157 | $forms[Cases::VINIT] = GeneralDeclension::getVinitCaseByAnimateness($forms, $animateness); |
||
158 | |||
159 | // TVORIT |
||
160 | // my personal rule |
||
161 | if ($last == 'ь' && $declension == GeneralDeclension::THIRD_DECLENSION && !in_array(S::slice($word, -2), array('чь', 'сь'))) { |
||
162 | $forms[Cases::TVORIT] = $prefix.'ми'; |
||
163 | } else { |
||
164 | $forms[Cases::TVORIT] = self::chooseVowelAfterConsonant($last, $soft_last && S::slice($word, -2, -1) != 'ч', $prefix.'ями', $prefix.'ами'); |
||
165 | } |
||
166 | |||
167 | // PREDLOJ |
||
168 | $forms[Cases::PREDLOJ] = self::chooseVowelAfterConsonant($last, $soft_last && S::slice($word, -2, -1) != 'ч', $prefix.'ях', $prefix.'ах'); |
||
169 | $forms[Cases::PREDLOJ] = self::choosePrepositionByFirstLetter($forms[Cases::PREDLOJ], 'об', 'о').' '.$forms[Cases::PREDLOJ]; |
||
170 | return $forms; |
||
171 | } |
||
172 | |||
189 |
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..