Skip to content

Commit 592e852

Browse files
committed
Add flag to TextReport constructor
Fix additional covered lines functionality
1 parent c3aab3c commit 592e852

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

phpunit.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
<directory suffix="Test.php">tests/tests</directory>
99
</testsuite>
1010

11-
<logging>
12-
<log type="coverage-clover" target="./build/clover.xml" />
13-
</logging>
14-
1511
<filter>
1612
<whitelist processUncoveredFilesFromWhitelist="true">
1713
<directory suffix=".php">src</directory>

src/CodeCoverage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data): void
626626
}
627627

628628
foreach ($fileData['functions'] as $functionName => $functionData) {
629-
// @todo - should this have a helper to merge covered paths?
630629
$this->data[$file]['paths'][$functionName] = $functionData['paths'];
631630

632631
foreach ($functionData['branches'] as $branchIndex => $branchData) {
@@ -840,7 +839,6 @@ private function addUncoveredFilesFromWhitelist(): void
840839
for ($line = 1; $line <= $lines; $line++) {
841840
$data[$uncoveredFile]['lines'][$line] = Driver::LINE_NOT_EXECUTED;
842841
}
843-
// @todo - do the same here with functions and paths
844842
}
845843

846844
$this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST');

src/Node/File.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,21 @@ private function calculateStatistics(): void
377377
unset($tokens);
378378

379379
foreach (\range(1, $this->linesOfCode['loc']) as $lineNumber) {
380-
if (isset($this->coverageData['lines'][$lineNumber])) {
381-
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
382-
$codeUnit['executableLines']++;
383-
}
380+
// Check to see if we've identified this line as executed, not executed, or not executable
381+
if (\array_key_exists($lineNumber, $this->coverageData['lines'])) {
382+
// If the element is null, that indicates this line is not executable
383+
if ($this->coverageData['lines'][$lineNumber] !== null) {
384+
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
385+
$codeUnit['executableLines']++;
386+
}
387+
388+
unset($codeUnit);
384389

385-
unset($codeUnit);
390+
$this->numExecutableLines++;
391+
}
386392

387-
$this->numExecutableLines++;
388393

389-
if (\count($this->coverageData['lines'][$lineNumber]) > 0) {
394+
if ($this->coverageData['lines'][$lineNumber]['pathCovered'] === true) {
390395
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
391396
$codeUnit['executedLines']++;
392397
}
@@ -472,6 +477,19 @@ private function calcAndApplyClassAggregate(
472477
foreach ($classOrTrait['methods'] as &$method) {
473478
$methodName = $method['methodName'];
474479

480+
if ($method['executableLines'] > 0) {
481+
$method['coverage'] = ($method['executedLines'] / $method['executableLines']) * 100;
482+
} else {
483+
$method['coverage'] = 100;
484+
}
485+
486+
$method['crap'] = $this->crap(
487+
$method['ccn'],
488+
$method['coverage']
489+
);
490+
491+
$classOrTrait['ccn'] += $method['ccn'];
492+
475493
if (isset($this->coverageData['paths'])) {
476494
$methodCoveragePath = $methodName;
477495

@@ -499,19 +517,6 @@ private function calcAndApplyClassAggregate(
499517
$this->numTestedPaths += $numExexutedPaths;
500518
}
501519

502-
if ($method['executableLines'] > 0) {
503-
$method['coverage'] = ($method['executedLines'] /
504-
$method['executableLines']) * 100;
505-
} else {
506-
$method['coverage'] = 100;
507-
}
508-
509-
$method['crap'] = $this->crap(
510-
$method['ccn'],
511-
$method['coverage']
512-
);
513-
514-
$classOrTrait['ccn'] += $method['ccn'];
515520
}
516521

517522
if (isset($this->coverageData['branches'])) {

0 commit comments

Comments
 (0)