Conditions | 17 |
Paths | 64 |
Total Lines | 63 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
156 | private function checkReplacementDataIssues() |
||
157 | { |
||
158 | $replacementDataObject = new LoadReplacementData( |
||
159 | $this->mu(), |
||
160 | $this->alternativePathForReplacementData, |
||
161 | $this->params |
||
162 | ); |
||
163 | $arr = $replacementDataObject->getReplacementArrays(null); |
||
164 | $arrTos = []; |
||
165 | $arrLanguages = $replacementDataObject->getLanguages(); |
||
166 | $fullFindArray = $replacementDataObject->getFlatFindArray(); |
||
167 | $fullReplaceArray = $replacementDataObject->getFlatReplacedArray(); |
||
168 | |||
169 | //1. check that one find may not stop another replacement. |
||
170 | foreach ($arrLanguages as $language) { |
||
171 | if (! isset($fullFindArray[$language])) { |
||
172 | continue; |
||
173 | } |
||
174 | unset($keyOuterDoneSoFar); |
||
175 | $keyOuterDoneSoFar = []; |
||
176 | foreach ($fullFindArray[$language] as $keyOuter => $findStringOuter) { |
||
177 | $keyOuterDoneSoFar[$keyOuter] = true; |
||
178 | foreach ($fullFindArray[$language] as $keyInner => $findStringInner) { |
||
179 | if (! isset($keyOuterDoneSoFar[$keyInner])) { |
||
180 | if ($keyOuter !== $keyInner) { |
||
181 | $findStringOuterReplaced = str_replace($findStringInner, '...', $findStringOuter); |
||
182 | if ($findStringOuter === $findStringInner || $findStringOuterReplaced !== $findStringOuter) { |
||
183 | $this->mu()->colourPrint(" |
||
184 | ERROR in ${language}: \t\t we are trying to find the same thing twice (A and B) |
||
185 | ---- A: (${keyOuter}): \t\t ${findStringOuter} |
||
186 | ---- B: (${keyInner}): \t\t ${findStringInner}"); |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | } |
||
193 | |||
194 | //2. check that a replacement is not mentioned before the it is being replaced |
||
195 | foreach ($arrLanguages as $language) { |
||
196 | if (! isset($fullReplaceArray[$language])) { |
||
197 | continue; |
||
198 | } |
||
199 | unset($keyOuterDoneSoFar); |
||
200 | $keyOuterDoneSoFar = []; |
||
201 | foreach ($fullReplaceArray[$language] as $keyOuter => $findStringOuter) { |
||
202 | $keyOuterDoneSoFar[$keyOuter] = true; |
||
203 | foreach ($fullFindArray[$language] as $keyInner => $findStringInner) { |
||
204 | if (isset($keyOuterDoneSoFar[$keyInner])) { |
||
205 | if ($keyOuter !== $keyInner) { |
||
206 | $findStringOuterReplaced = str_replace($findStringInner, '...', $findStringOuter); |
||
207 | if ($findStringOuter === $findStringInner || $findStringOuterReplaced !== $findStringOuter) { |
||
208 | $this->mu()->colourPrint(" |
||
209 | ERROR in ${language}: \t\t there is a replacement (A) that was earlier tried to be found (B). |
||
210 | ---- A: (${keyOuter}): \t\t ${findStringOuter} |
||
211 | ---- B: (${keyInner}): \t\t ${findStringInner}"); |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | } |
||
218 | $this->mu()->colourPrint(''); |
||
219 | } |
||
221 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.