Conditions | 38 |
Paths | > 20000 |
Total Lines | 175 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
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 |
||
193 | protected function calculateCoverageThreshold($filename, $coverageInformation) |
||
194 | { |
||
195 | $classes = PHPUnitUtil::getDefinedClasses($filename, $this->classpath); |
||
196 | |||
197 | if (is_array($classes)) { |
||
198 | foreach ($classes as $className) { |
||
199 | // Skip class if excluded from coverage threshold validation |
||
200 | if ($this->excludes !== null) { |
||
201 | if (in_array($className, $this->excludes->getExcludedClasses())) { |
||
202 | continue; |
||
203 | } |
||
204 | } |
||
205 | |||
206 | $reflection = new \ReflectionClass($className); |
||
207 | $classStartLine = $reflection->getStartLine(); |
||
208 | |||
209 | // Strange PHP5 reflection bug, classes without parent class |
||
210 | // or implemented interfaces seem to start one line off |
||
211 | if ( |
||
212 | $reflection->getParentClass() === null |
||
213 | && count($reflection->getInterfaces()) === 0 |
||
214 | ) { |
||
215 | unset($coverageInformation[$classStartLine + 1]); |
||
216 | } else { |
||
217 | unset($coverageInformation[$classStartLine]); |
||
218 | } |
||
219 | |||
220 | reset($coverageInformation); |
||
221 | |||
222 | $methods = $reflection->getMethods(); |
||
223 | |||
224 | foreach ($methods as $method) { |
||
225 | // PHP5 reflection considers methods of a parent class |
||
226 | // to be part of a subclass, we don't |
||
227 | if ($method->getDeclaringClass()->getName() != $reflection->getName()) { |
||
228 | continue; |
||
229 | } |
||
230 | |||
231 | // Skip method if excluded from coverage threshold validation |
||
232 | if ($this->excludes !== null) { |
||
233 | $excludedMethods = $this->excludes->getExcludedMethods(); |
||
234 | |||
235 | if (isset($excludedMethods[$className])) { |
||
236 | if ( |
||
237 | in_array($method->getName(), $excludedMethods[$className]) |
||
238 | || in_array($method->getName() . '()', $excludedMethods[$className]) |
||
239 | ) { |
||
240 | continue; |
||
241 | } |
||
242 | } |
||
243 | } |
||
244 | |||
245 | $methodStartLine = $method->getStartLine(); |
||
246 | $methodEndLine = $method->getEndLine(); |
||
247 | |||
248 | // small fix for XDEBUG_CC_UNUSED |
||
249 | if (isset($coverageInformation[$methodStartLine])) { |
||
250 | unset($coverageInformation[$methodStartLine]); |
||
251 | } |
||
252 | |||
253 | if (isset($coverageInformation[$methodEndLine])) { |
||
254 | unset($coverageInformation[$methodEndLine]); |
||
255 | } |
||
256 | |||
257 | if ($method->isAbstract()) { |
||
258 | continue; |
||
259 | } |
||
260 | |||
261 | $lineNr = key($coverageInformation); |
||
262 | |||
263 | while ($lineNr !== null && $lineNr < $methodStartLine) { |
||
264 | next($coverageInformation); |
||
265 | $lineNr = key($coverageInformation); |
||
266 | } |
||
267 | |||
268 | $methodStatementsCovered = 0; |
||
269 | $methodStatementCount = 0; |
||
270 | |||
271 | while ($lineNr !== null && $lineNr <= $methodEndLine) { |
||
272 | $methodStatementCount++; |
||
273 | |||
274 | $lineCoverageInfo = $coverageInformation[$lineNr]; |
||
275 | // set covered when CODE is other than -1 (not executed) |
||
276 | if ($lineCoverageInfo > 0 || $lineCoverageInfo === -2) { |
||
277 | $methodStatementsCovered++; |
||
278 | } |
||
279 | |||
280 | next($coverageInformation); |
||
281 | $lineNr = key($coverageInformation); |
||
282 | } |
||
283 | |||
284 | if ($methodStatementCount > 0) { |
||
285 | $methodCoverage = ($methodStatementsCovered |
||
286 | / $methodStatementCount) * 100; |
||
287 | } else { |
||
288 | $methodCoverage = 0; |
||
289 | } |
||
290 | |||
291 | if ($methodCoverage < $this->perMethod && !$method->isAbstract()) { |
||
292 | throw new BuildException( |
||
293 | 'The coverage (' . round($methodCoverage, 2) . '%) ' |
||
294 | . 'for method "' . $method->getName() . '" is lower' |
||
295 | . ' than the specified threshold (' |
||
296 | . $this->perMethod . '%), see file: "' |
||
297 | . $filename . '"' |
||
298 | ); |
||
299 | } |
||
300 | |||
301 | if ( |
||
302 | $methodCoverage < $this->perMethod |
||
303 | && $method->isAbstract() |
||
304 | && $this->verbose === true |
||
305 | ) { |
||
306 | $this->log( |
||
307 | 'Skipped coverage threshold for abstract method "' |
||
308 | . $method->getName() . '"' |
||
309 | ); |
||
310 | } |
||
311 | |||
312 | // store the minimum coverage value for logging (see #466) |
||
313 | if ($this->minMethodCoverageFound !== null) { |
||
314 | if ($this->minMethodCoverageFound > $methodCoverage) { |
||
315 | $this->minMethodCoverageFound = $methodCoverage; |
||
316 | } |
||
317 | } else { |
||
318 | $this->minMethodCoverageFound = $methodCoverage; |
||
319 | } |
||
320 | } |
||
321 | |||
322 | $classStatementCount = count($coverageInformation); |
||
323 | $classStatementsCovered = count( |
||
324 | array_filter( |
||
325 | $coverageInformation, |
||
326 | [$this, 'filterCovered'] |
||
327 | ) |
||
328 | ); |
||
329 | |||
330 | if ($classStatementCount > 0) { |
||
331 | $classCoverage = ($classStatementsCovered |
||
332 | / $classStatementCount) * 100; |
||
333 | } else { |
||
334 | $classCoverage = 0; |
||
335 | } |
||
336 | |||
337 | if ($classCoverage < $this->perClass && !$reflection->isAbstract()) { |
||
338 | throw new BuildException( |
||
339 | 'The coverage (' . round($classCoverage, 2) . '%) for class "' |
||
340 | . $reflection->getName() . '" is lower than the ' |
||
341 | . 'specified threshold (' . $this->perClass . '%), ' |
||
342 | . 'see file: "' . $filename . '"' |
||
343 | ); |
||
344 | } |
||
345 | |||
346 | if ( |
||
347 | $classCoverage < $this->perClass |
||
348 | && $reflection->isAbstract() |
||
349 | && $this->verbose === true |
||
350 | ) { |
||
351 | $this->log( |
||
352 | 'Skipped coverage threshold for abstract class "' |
||
353 | . $reflection->getName() . '"' |
||
354 | ); |
||
355 | } |
||
356 | |||
357 | // store the minimum coverage value for logging (see #466) |
||
358 | if ($this->minClassCoverageFound !== null) { |
||
359 | if ($this->minClassCoverageFound > $classCoverage) { |
||
360 | $this->minClassCoverageFound = $classCoverage; |
||
361 | } |
||
362 | } else { |
||
363 | $this->minClassCoverageFound = $classCoverage; |
||
364 | } |
||
365 | |||
366 | $this->projectStatementCount += $classStatementCount; |
||
367 | $this->projectStatementsCovered += $classStatementsCovered; |
||
368 | } |
||
439 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths