52% of 2059OPs |
55% of 492Lines |
40% of 520Branches |
1% of 4705Paths |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum\score; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum, |
| 7 |
mageekguy\atoum\score, |
| 8 |
mageekguy\atoum\exceptions |
| 9 |
; |
| 10 |
|
| 11 |
class coverage implements \countable, \serializable |
| 12 |
{
|
| 13 |
protected $adapter = null; |
| 14 |
protected $reflectionClassFactory = null; |
| 15 |
protected $classes = array(); |
| 16 |
protected $methods = array(); |
| 17 |
protected $paths = array(); |
| 18 |
protected $branches = array(); |
| 19 |
protected $excludedMethods = array(); |
| 20 |
protected $excludedClasses = array(); |
| 21 |
protected $excludedNamespaces = array(); |
| 22 |
protected $excludedDirectories = array(); |
| 23 |
|
| 24 |
public function __construct(atoum\adapter $adapter = null, \closure $reflectionClassFactory = null)100% |
| 25 |
{
|
| 26 |
$this |
| 27 |
->setAdapter($adapter) |
| 28 |
->setReflectionClassFactory($reflectionClassFactory) |
| 29 |
; |
| 30 |
} |
| 31 |
|
| 32 |
public function setAdapter(atoum\adapter $adapter = null)100% |
| 33 |
{
|
| 34 |
$this->adapter = $adapter ?: new atoum\adapter(); |
| 35 |
|
| 36 |
return $this; |
| 37 |
} |
| 38 |
|
| 39 |
public function getAdapter()100% |
| 40 |
{
|
| 41 |
return $this->adapter; |
| 42 |
} |
| 43 |
|
| 44 |
public function setReflectionClassFactory(\closure $factory = null)100% |
| 45 |
{
|
| 46 |
$this->reflectionClassFactory = $factory ?: function($class) { return new \reflectionClass($class); };
|
| 47 |
|
| 48 |
return $this; |
| 49 |
} |
| 50 |
|
| 51 |
public function getReflectionClassFactory()100% |
| 52 |
{
|
| 53 |
return $this->reflectionClassFactory; |
| 54 |
} |
| 55 |
|
| 56 |
public function serialize()10% |
| 57 |
{
|
| 58 |
return serialize(array( |
| 59 |
$this->classes, |
| 60 |
$this->methods, |
| 61 |
$this->paths, |
| 62 |
$this->branches, |
| 63 |
$this->excludedClasses, |
| 64 |
$this->excludedNamespaces, |
| 65 |
$this->excludedDirectories |
| 66 |
) |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
public function unserialize($string, \closure $reflectionClassFactory = null)0% |
| 71 |
{
|
| 72 |
$this->setReflectionClassFactory($reflectionClassFactory); |
| 73 |
|
| 74 |
list( |
| 75 |
$this->classes, |
| 76 |
$this->methods, |
| 77 |
$this->paths, |
| 78 |
$this->branches, |
| 79 |
$this->excludedClasses, |
| 80 |
$this->excludedNamespaces, |
| 81 |
$this->excludedDirectories |
| 82 |
) = unserialize($string); |
| 83 |
|
| 84 |
return $this; |
| 85 |
} |
| 86 |
|
| 87 |
public function getClasses()100% |
| 88 |
{
|
| 89 |
return $this->classes; |
| 90 |
} |
| 91 |
|
| 92 |
public function getMethods()100% |
| 93 |
{
|
| 94 |
return $this->methods; |
| 95 |
} |
| 96 |
|
| 97 |
public function getPaths()100% |
| 98 |
{
|
| 99 |
return $this->paths; |
| 100 |
} |
| 101 |
|
| 102 |
public function getBranches()100% |
| 103 |
{
|
| 104 |
return $this->branches; |
| 105 |
} |
| 106 |
|
| 107 |
public function reset()100% |
| 108 |
{
|
| 109 |
$this->classes = array(); |
| 110 |
$this->methods = array(); |
| 111 |
$this->paths = array(); |
| 112 |
$this->branches = array(); |
| 113 |
|
| 114 |
return $this; |
| 115 |
} |
| 116 |
|
| 117 |
public function resetExcludedMethods()100% |
| 118 |
{
|
| 119 |
$this->excludedMethods = array(); |
| 120 |
|
| 121 |
return $this; |
| 122 |
} |
| 123 |
|
| 124 |
public function resetExcludedClasses()100% |
| 125 |
{
|
| 126 |
$this->excludedClasses = array(); |
| 127 |
|
| 128 |
return $this; |
| 129 |
} |
| 130 |
|
| 131 |
public function resetExcludedNamespaces()100% |
| 132 |
{
|
| 133 |
$this->excludedNamespaces = array(); |
| 134 |
|
| 135 |
return $this; |
| 136 |
} |
| 137 |
|
| 138 |
public function resetExcludedDirectories()100% |
| 139 |
{
|
| 140 |
$this->excludedDirectories = array(); |
| 141 |
|
| 142 |
return $this; |
| 143 |
} |
| 144 |
|
| 145 |
public function addXdebugDataForTest(atoum\test $test, array $data)100% |
| 146 |
{
|
| 147 |
return $this->addXdebugDataForClass($test->getTestedClassName(), $data); |
| 148 |
} |
| 149 |
|
| 150 |
public function addXdebugDataForClass($class, array $data)83% |
| 151 |
{
|
| 152 |
try |
| 153 |
{
|
| 154 |
$reflectedClass = call_user_func($this->reflectionClassFactory, $class); |
| 155 |
|
| 156 |
if ($this->isExcluded($reflectedClass) === false) |
| 157 |
{
|
| 158 |
$reflectedClassName = $reflectedClass->getName(); |
| 159 |
|
| 160 |
if (isset($this->classes[$reflectedClassName]) === false) |
| 161 |
{
|
| 162 |
$this->classes[$reflectedClassName] = $reflectedClass->getFileName(); |
| 163 |
$this->methods[$reflectedClassName] = array(); |
| 164 |
|
| 165 |
foreach ($reflectedClass->getMethods() as $method) |
| 166 |
{
|
| 167 |
if ($method->isAbstract() === false && $this->isInExcludedMethods($method->getName()) === false) |
| 168 |
{
|
| 169 |
$declaringClass = $this->getDeclaringClass($method); |
| 170 |
|
| 171 |
if ($this->isExcluded($declaringClass) === false) |
| 172 |
{
|
| 173 |
$declaringClassName = $declaringClass->getName(); |
| 174 |
$declaringClassFile = $declaringClass->getFilename(); |
| 175 |
|
| 176 |
if (isset($data[$declaringClassFile]['functions'][$declaringClassName . '->' . $method->getName()])) |
| 177 |
{
|
| 178 |
$this->paths[$declaringClassName][$method->getName()] = $data[$declaringClassFile]['functions'][$declaringClassName . '->' . $method->getName()]['paths']; |
| 179 |
$this->branches[$declaringClassName][$method->getName()] = $data[$declaringClassFile]['functions'][$declaringClassName . '->' . $method->getName()]['branches']; |
| 180 |
} |
| 181 |
|
| 182 |
if (isset($this->classes[$declaringClassName]) === false) |
| 183 |
{
|
| 184 |
$this->classes[$declaringClassName] = $declaringClassFile; |
| 185 |
$this->methods[$declaringClassName] = array(); |
| 186 |
} |
| 187 |
|
| 188 |
if (isset($data[$declaringClassFile]) === true) |
| 189 |
{
|
| 190 |
for ($line = $method->getStartLine(), $endLine = $method->getEndLine(); $line <= $endLine; $line++) |
| 191 |
{
|
| 192 |
if (isset($data[$declaringClassFile]['lines'][$line]) === true && (isset($this->methods[$declaringClassName][$method->getName()][$line]) === false || $this->methods[$declaringClassName][$method->getName()][$line] < $data[$declaringClassFile][$line])) |
| 193 |
{
|
| 194 |
$this->methods[$declaringClassName][$method->getName()][$line] = $data[$declaringClassFile]['lines'][$line]; |
| 195 |
} |
| 196 |
|
| 197 |
if (isset($data[$declaringClassFile][$line]) === true && (isset($this->methods[$declaringClassName][$method->getName()][$line]) === false || $this->methods[$declaringClassName][$method->getName()][$line] < $data[$declaringClassFile][$line])) |
| 198 |
{
|
| 199 |
$this->methods[$declaringClassName][$method->getName()][$line] = $data[$declaringClassFile][$line]; |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
catch (\exception $exception) {}
|
| 210 |
|
| 211 |
return $this; |
| 212 |
} |
| 213 |
|
| 214 |
public function merge(score\coverage $coverage)45% |
| 215 |
{
|
| 216 |
$paths = $coverage->getPaths(); |
| 217 |
$branches = $coverage->getBranches(); |
| 218 |
$classes = $coverage->getClasses(); |
| 219 |
$methods = $coverage->getMethods(); |
| 220 |
|
| 221 |
foreach ($methods as $class => $methods) |
| 222 |
{
|
| 223 |
$reflectedClass = call_user_func($this->reflectionClassFactory, $class); |
| 224 |
|
| 225 |
if ($this->isExcluded($reflectedClass) === false) |
| 226 |
{
|
| 227 |
if (isset($this->classes[$class]) === false) |
| 228 |
{
|
| 229 |
$this->classes[$class] = $classes[$class]; |
| 230 |
} |
| 231 |
|
| 232 |
if (isset($paths[$class]) && isset($this->paths[$class]) === false) |
| 233 |
{
|
| 234 |
$this->paths[$class] = $paths[$class]; |
| 235 |
} |
| 236 |
|
| 237 |
if (isset($branches[$class]) && isset($this->branches[$class]) === false) |
| 238 |
{
|
| 239 |
$this->branches[$class] = $branches[$class]; |
| 240 |
} |
| 241 | |
| 242 |
foreach ($methods as $method => $lines) |
| 243 |
{
|
| 244 |
if (isset($paths[$class]) === true) |
| 245 |
{
|
| 246 |
if (isset($this->paths[$class][$method]) === false) |
| 247 |
{
|
| 248 |
$this->paths[$class][$method] = $paths[$class][$method]; |
| 249 |
} |
| 250 |
|
| 251 |
foreach ($paths[$class][$method] as $index => $path) |
| 252 |
{
|
| 253 |
if ($this->paths[$class][$method][$index]['hit'] < $path['hit']) |
| 254 |
{
|
| 255 |
$this->paths[$class][$method][$index]['hit'] = $path['hit']; |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
if (isset($branches[$class]) === true) |
| 261 |
{
|
| 262 |
if (isset($this->branches[$class][$method]) === false) |
| 263 |
{
|
| 264 |
$this->branches[$class][$method] = $branches[$class][$method]; |
| 265 |
} |
| 266 |
|
| 267 |
foreach ($branches[$class][$method] as $index => $branch) |
| 268 |
{
|
| 269 |
if ($this->branches[$class][$method][$index]['hit'] < $branch['hit']) |
| 270 |
{
|
| 271 |
$this->branches[$class][$method][$index]['hit'] = $branch['hit']; |
| 272 |
} |
| 273 |
|
| 274 |
foreach ($branch['out'] as $outIndex => $outOp) |
| 275 |
{
|
| 276 |
if (isset($this->branches[$class][$method][$index]['out'][$outIndex]) === false) |
| 277 |
{
|
| 278 |
$this->branches[$class][$method][$index]['out'][$outIndex] = $outOp; |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
foreach ($branch['out_hit'] as $outIndex => $hit) |
| 283 |
{
|
| 284 |
if (isset($this->branches[$class][$method][$index]['out_hit'][$outIndex]) === false) |
| 285 |
{
|
| 286 |
$this->branches[$class][$method][$index]['out_hit'][$outIndex] = $hit; |
| 287 |
} |
| 288 |
else |
| 289 |
{
|
| 290 |
if ($this->branches[$class][$method][$index]['out_hit'][$outIndex] < $hit) |
| 291 |
{
|
| 292 |
$this->branches[$class][$method][$index]['out_hit'][$outIndex] = $hit; |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
if (isset($this->methods[$class][$method]) === true || $this->isExcluded($this->getDeclaringClass($reflectedClass->getMethod($method))) === false) |
| 300 |
{
|
| 301 |
foreach ($lines as $line => $call) |
| 302 |
{
|
| 303 |
if (isset($this->methods[$class][$method][$line]) === false || $this->methods[$class][$method][$line] < $call) |
| 304 |
{
|
| 305 |
$this->methods[$class][$method][$line] = $call; |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
return $this; |
| 314 |
} |
| 315 |
|
| 316 |
public function getValue()100% |
| 317 |
{
|
| 318 |
$value = null; |
| 319 |
|
| 320 |
if (sizeof($this) > 0) |
| 321 |
{
|
| 322 |
$totalLines = 0; |
| 323 |
$coveredLines = 0; |
| 324 |
|
| 325 |
foreach ($this->methods as $methods) |
| 326 |
{
|
| 327 |
foreach ($methods as $lines) |
| 328 |
{
|
| 329 |
foreach ($lines as $call) |
| 330 |
{
|
| 331 |
if ($call >= -1) |
| 332 |
{
|
| 333 |
$totalLines++; |
| 334 |
} |
| 335 |
|
| 336 |
if ($call === 1) |
| 337 |
{
|
| 338 |
$coveredLines++; |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
if ($totalLines > 0) |
| 345 |
{
|
| 346 |
$value = (float) $coveredLines / $totalLines; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
return $value; |
| 351 |
} |
| 352 |
|
| 353 |
public function getPathsCoverageValue()0% |
| 354 |
{
|
| 355 |
$value = null; |
| 356 |
|
| 357 |
if (sizeof($this->getPaths()) > 0) |
| 358 |
{
|
| 359 |
$totalPaths = 0; |
| 360 |
$coveredPaths = 0; |
| 361 |
|
| 362 |
foreach ($this->paths as $methods) |
| 363 |
{
|
| 364 |
foreach ($methods as $method) |
| 365 |
{
|
| 366 |
foreach ($method as $path) |
| 367 |
{
|
| 368 |
$totalPaths++; |
| 369 |
|
| 370 |
if ($path['hit'] === 1) |
| 371 |
{
|
| 372 |
$coveredPaths++; |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
if ($totalPaths > 0) |
| 379 |
{
|
| 380 |
$value = (float) $coveredPaths / $totalPaths; |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
return $value; |
| 385 |
} |
| 386 |
|
| 387 |
public function getBranchesCoverageValue()4% |
| 388 |
{
|
| 389 |
$value = null; |
| 390 |
|
| 391 |
if (sizeof($this->getBranches()) > 0) |
| 392 |
{
|
| 393 |
$totalBranches = 0; |
| 394 |
$coveredBranches = 0; |
| 395 |
|
| 396 |
foreach ($this->branches as $methods) |
| 397 |
{
|
| 398 |
foreach ($methods as $method) |
| 399 |
{
|
| 400 |
foreach ($method as $node) |
| 401 |
{
|
| 402 |
foreach ($node['out'] as $index => $out) |
| 403 |
{
|
| 404 |
$totalBranches++; |
| 405 |
|
| 406 |
if ($node['out_hit'][$index] === 1) |
| 407 |
{
|
| 408 |
$coveredBranches++; |
| 409 |
} |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
if ($totalBranches > 0) |
| 416 |
{
|
| 417 |
$value = (float) $coveredBranches / $totalBranches; |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
return $value; |
| 422 |
} |
| 423 |
|
| 424 |
public function getValueForClass($class)100% |
| 425 |
{
|
| 426 |
$value = null; |
| 427 |
|
| 428 |
if (isset($this->methods[$class]) === true) |
| 429 |
{
|
| 430 |
$totalLines = 0; |
| 431 |
$coveredLines = 0; |
| 432 |
|
| 433 |
foreach ($this->methods[$class] as $lines) |
| 434 |
{
|
| 435 |
foreach ($lines as $call) |
| 436 |
{
|
| 437 |
if ($call >= -1) |
| 438 |
{
|
| 439 |
$totalLines++; |
| 440 |
} |
| 441 |
|
| 442 |
if ($call === 1) |
| 443 |
{
|
| 444 |
$coveredLines++; |
| 445 |
} |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
if ($totalLines > 0) |
| 450 |
{
|
| 451 |
$value = (float) $coveredLines / $totalLines; |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
return $value; |
| 456 |
} |
| 457 |
|
| 458 |
public function getPathsCoverageValueForClass($class)0% |
| 459 |
{
|
| 460 |
$value = null; |
| 461 |
|
| 462 |
if (isset($this->paths[$class]) === true) |
| 463 |
{
|
| 464 |
$totalPaths = 0; |
| 465 |
$coveredPaths = 0; |
| 466 |
|
| 467 |
foreach ($this->paths[$class] as $method) |
| 468 |
{
|
| 469 |
foreach ($method as $path) |
| 470 |
{
|
| 471 |
$totalPaths++; |
| 472 |
|
| 473 |
if ($path['hit'] === 1) |
| 474 |
{
|
| 475 |
$coveredPaths++; |
| 476 |
} |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
if ($totalPaths > 0) |
| 481 |
{
|
| 482 |
$value = (float) $coveredPaths / $totalPaths; |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
return $value; |
| 487 |
} |
| 488 |
|
| 489 |
public function getBranchesCoverageValueForClass($class)5% |
| 490 |
{
|
| 491 |
$value = null; |
| 492 |
|
| 493 |
if (isset($this->branches[$class]) === true) |
| 494 |
{
|
| 495 |
$totalPaths = 0; |
| 496 |
$coveredPaths = 0; |
| 497 |
|
| 498 |
foreach ($this->branches[$class] as $method) |
| 499 |
{
|
| 500 |
foreach ($method as $path) |
| 501 |
{
|
| 502 |
$totalPaths++; |
| 503 |
|
| 504 |
if ($path['hit'] === 1) |
| 505 |
{
|
| 506 |
$coveredPaths++; |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
if ($totalPaths > 0) |
| 512 |
{
|
| 513 |
$value = (float) $coveredPaths / $totalPaths; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
return $value; |
| 518 |
} |
| 519 |
|
| 520 |
public function getCoverageForClass($class)100% |
| 521 |
{
|
| 522 |
$coverage = array(); |
| 523 |
|
| 524 |
$class = (string) $class; |
| 525 |
|
| 526 |
if (isset($this->methods[$class]) === true && $this->isInExcludedClasses($class) === false) |
| 527 |
{
|
| 528 |
$coverage = $this->methods[$class]; |
| 529 |
} |
| 530 |
|
| 531 |
return $coverage; |
| 532 |
} |
| 533 |
|
| 534 |
public function getBranchesCoverageForClass($class)0% |
| 535 |
{
|
| 536 |
$coverage = array(); |
| 537 |
|
| 538 |
$class = (string) $class; |
| 539 |
|
| 540 |
if (isset($this->branches[$class]) === true && $this->isInExcludedClasses($class) === false) |
| 541 |
{
|
| 542 |
$coverage = $this->branches[$class]; |
| 543 |
} |
| 544 |
|
| 545 |
return $coverage; |
| 546 |
} |
| 547 |
|
| 548 |
public function getPathsCoverageForClass($class)0% |
| 549 |
{
|
| 550 |
$coverage = array(); |
| 551 |
|
| 552 |
$class = (string) $class; |
| 553 |
|
| 554 |
if (isset($this->paths[$class]) === true && $this->isInExcludedClasses($class) === false) |
| 555 |
{
|
| 556 |
$coverage = $this->paths[$class]; |
| 557 |
} |
| 558 |
|
| 559 |
return $coverage; |
| 560 |
} |
| 561 |
|
| 562 |
public function getNumberOfCoverableLinesInClass($class)100% |
| 563 |
{
|
| 564 |
$coverableLines = 0; |
| 565 |
|
| 566 |
$class = (string) $class; |
| 567 |
|
| 568 |
if (isset($this->methods[$class]) === true && $this->isInExcludedClasses($class) === false) |
| 569 |
{
|
| 570 |
foreach ($this->methods[$class] as $lines) |
| 571 |
{
|
| 572 |
foreach ($lines as $call) |
| 573 |
{
|
| 574 |
if ($call >= -1) |
| 575 |
{
|
| 576 |
$coverableLines++; |
| 577 |
} |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
return $coverableLines; |
| 583 |
} |
| 584 |
|
| 585 |
public function getNumberOfCoveredLinesInClass($class)100% |
| 586 |
{
|
| 587 |
$coveredLines = 0; |
| 588 |
|
| 589 |
$class = (string) $class; |
| 590 |
|
| 591 |
if (isset($this->methods[$class]) === true && $this->isInExcludedClasses($class) === false) |
| 592 |
{
|
| 593 |
foreach ($this->methods[$class] as $lines) |
| 594 |
{
|
| 595 |
foreach ($lines as $call) |
| 596 |
{
|
| 597 |
if ($call === 1) |
| 598 |
{
|
| 599 |
$coveredLines++; |
| 600 |
} |
| 601 |
} |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
return $coveredLines; |
| 606 |
} |
| 607 |
|
| 608 |
public function getValueForMethod($class, $method)100% |
| 609 |
{
|
| 610 |
$value = null; |
| 611 |
|
| 612 |
if (isset($this->methods[$class][$method]) === true) |
| 613 |
{
|
| 614 |
$totalLines = 0; |
| 615 |
$coveredLines = 0; |
| 616 |
|
| 617 |
foreach ($this->methods[$class][$method] as $call) |
| 618 |
{
|
| 619 |
if ($call >= -1) |
| 620 |
{
|
| 621 |
$totalLines++; |
| 622 |
} |
| 623 |
|
| 624 |
if ($call === 1) |
| 625 |
{
|
| 626 |
$coveredLines++; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
if ($totalLines > 0) |
| 631 |
{
|
| 632 |
$value = (float) $coveredLines / $totalLines; |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
return $value; |
| 637 |
} |
| 638 |
|
| 639 |
public function getPathsCoverageValueForMethod($class, $method)0% |
| 640 |
{
|
| 641 |
$value = null; |
| 642 |
|
| 643 |
if (isset($this->paths[$class][$method]) === true) |
| 644 |
{
|
| 645 |
$totalPaths = 0; |
| 646 |
$coveredPaths = 0; |
| 647 |
|
| 648 |
foreach ($this->paths[$class][$method] as $path) |
| 649 |
{
|
| 650 |
$totalPaths++; |
| 651 |
|
| 652 |
if ($path['hit'] === 1) |
| 653 |
{
|
| 654 |
$coveredPaths++; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
if ($totalPaths > 0) |
| 659 |
{
|
| 660 |
$value = (float) $coveredPaths / $totalPaths; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
return $value; |
| 665 |
} |
| 666 |
|
| 667 |
public function getBranchesCoverageValueForMethod($class, $method)0% |
| 668 |
{
|
| 669 |
$value = null; |
| 670 |
|
| 671 |
if (isset($this->branches[$class][$method]) === true) |
| 672 |
{
|
| 673 |
$totalBranches = 0; |
| 674 |
$coveredBranches = 0; |
| 675 |
|
| 676 |
foreach ($this->branches[$class][$method] as $node) |
| 677 |
{
|
| 678 |
|
| 679 |
foreach ($node['out'] as $index => $out) |
| 680 |
{
|
| 681 |
$totalBranches++; |
| 682 |
|
| 683 |
if ($node['out_hit'][$index] === 1) |
| 684 |
{
|
| 685 |
$coveredBranches++; |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
if ($totalBranches > 0) |
| 691 |
{
|
| 692 |
$value = (float) $coveredBranches / $totalBranches; |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
return $value; |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
public function getCoverageForMethod($class, $method)100% |
| 701 |
{
|
| 702 |
$class = $this->getCoverageForClass($class); |
| 703 |
|
| 704 |
return (isset($class[$method]) === false ? array() : $class[$method]); |
| 705 |
} |
| 706 |
|
| 707 |
public function excludeMethod($method)100% |
| 708 |
{
|
| 709 |
$method = (string) $method; |
| 710 |
|
| 711 |
if (in_array($method, $this->excludedMethods) === false) |
| 712 |
{
|
| 713 |
$this->excludedMethods[] = $method; |
| 714 |
} |
| 715 |
|
| 716 |
return $this; |
| 717 |
} |
| 718 |
|
| 719 |
public function getExcludedMethods()100% |
| 720 |
{
|
| 721 |
return $this->excludedMethods; |
| 722 |
} |
| 723 |
|
| 724 |
public function excludeClass($class)100% |
| 725 |
{
|
| 726 |
$class = (string) $class; |
| 727 |
|
| 728 |
if (in_array($class, $this->excludedClasses) === false) |
| 729 |
{
|
| 730 |
$this->excludedClasses[] = $class; |
| 731 |
} |
| 732 |
|
| 733 |
return $this; |
| 734 |
} |
| 735 |
|
| 736 |
public function getExcludedClasses()100% |
| 737 |
{
|
| 738 |
return $this->excludedClasses; |
| 739 |
} |
| 740 |
|
| 741 |
public function excludeNamespace($namespace)100% |
| 742 |
{
|
| 743 |
$namespace = trim((string) $namespace, '\\'); |
| 744 |
|
| 745 |
if (in_array($namespace, $this->excludedNamespaces) === false) |
| 746 |
{
|
| 747 |
$this->excludedNamespaces[] = $namespace; |
| 748 |
} |
| 749 |
|
| 750 |
return $this; |
| 751 |
} |
| 752 |
|
| 753 |
public function getExcludedNamespaces()100% |
| 754 |
{
|
| 755 |
return $this->excludedNamespaces; |
| 756 |
} |
| 757 |
|
| 758 |
public function excludeDirectory($directory)100% |
| 759 |
{
|
| 760 |
$directory = rtrim((string) $directory, DIRECTORY_SEPARATOR); |
| 761 |
|
| 762 |
if (in_array($directory, $this->excludedDirectories) === false) |
| 763 |
{
|
| 764 |
$this->excludedDirectories[] = $directory; |
| 765 |
} |
| 766 |
|
| 767 |
return $this; |
| 768 |
} |
| 769 |
|
| 770 |
public function getExcludedDirectories()100% |
| 771 |
{
|
| 772 |
return $this->excludedDirectories; |
| 773 |
} |
| 774 |
|
| 775 |
public function count()100% |
| 776 |
{
|
| 777 |
return sizeof($this->methods); |
| 778 |
} |
| 779 |
|
| 780 |
public function isInExcludedMethods($method)100% |
| 781 |
{
|
| 782 |
foreach ($this->excludedMethods as $pattern) |
| 783 |
{
|
| 784 |
$matches = @preg_match($pattern, $method); |
| 785 |
|
| 786 |
if (false === $matches && $pattern === $method) |
| 787 |
{
|
| 788 |
return true; |
| 789 |
} |
| 790 |
|
| 791 |
if ($matches > 0) |
| 792 |
{
|
| 793 |
return true; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
return false; |
| 798 |
} |
| 799 |
|
| 800 |
public function isInExcludedClasses($class)100% |
| 801 |
{
|
| 802 |
return (in_array($class, $this->excludedClasses) === true); |
| 803 |
} |
| 804 |
|
| 805 |
public function isInExcludedNamespaces($class)100% |
| 806 |
{
|
| 807 |
return self::itemIsExcluded($this->excludedNamespaces, $class, '\\'); |
| 808 |
} |
| 809 |
|
| 810 |
public function isInExcludedDirectories($file)100% |
| 811 |
{
|
| 812 |
return self::itemIsExcluded($this->excludedDirectories, $file, DIRECTORY_SEPARATOR); |
| 813 |
} |
| 814 |
|
| 815 |
protected function isExcluded(\reflectionClass $class)100% |
| 816 |
{
|
| 817 |
$className = $class->getName(); |
| 818 |
|
| 819 |
if ($this->isInExcludedClasses($className) === true || $this->isInExcludedNamespaces($className) === true) |
| 820 |
{
|
| 821 |
return true; |
| 822 |
} |
| 823 |
else |
| 824 |
{
|
| 825 |
$fileName = $class->getFileName(); |
| 826 |
|
| 827 |
return ($fileName === false || $this->isInExcludedDirectories($fileName) === true); |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
protected function getDeclaringClass(\reflectionMethod $method)26% |
| 832 |
{
|
| 833 |
$declaringClass = $method->getDeclaringClass(); |
| 834 |
|
| 835 |
$traits = ($this->adapter->method_exists($declaringClass, 'getTraits') === false ? array() : $declaringClass->getTraits()); |
| 836 |
|
| 837 |
if (sizeof($traits) > 0) |
| 838 |
{
|
| 839 |
$methodFileName = $method->getFileName(); |
| 840 |
|
| 841 |
if ($methodFileName !== $declaringClass->getFileName() || $method->getStartLine() < $declaringClass->getStartLine() || $method->getEndLine() > $declaringClass->getEndLine()) |
| 842 |
{
|
| 843 |
if (sizeof($traits) > 0) |
| 844 |
{
|
| 845 |
$methodName = $method->getName(); |
| 846 |
|
| 847 |
foreach ($traits as $trait) |
| 848 |
{
|
| 849 |
if ($methodFileName === $trait->getFileName() && $trait->hasMethod($methodName) === true) |
| 850 |
{
|
| 851 |
return $trait; |
| 852 |
} |
| 853 |
} |
| 854 |
} |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
return $declaringClass; |
| 859 |
} |
| 860 |
|
| 861 |
protected static function itemIsExcluded(array $excludedItems, $item, $delimiter)100% |
| 862 |
{
|
| 863 |
foreach ($excludedItems as $excludedItem) |
| 864 |
{
|
| 865 |
$excludedItem .= $delimiter; |
| 866 |
|
| 867 |
if (substr($item, 0, strlen($excludedItem)) === $excludedItem) |
| 868 |
{
|
| 869 |
return true; |
| 870 |
} |
| 871 |
} |
| 872 |
|
| 873 |
return false; |
| 874 |
} |
| 875 |
} |