Skip to content

Commit 85548b8

Browse files
committed
Add flag to TextReport constructor
Fix additional covered lines functionality
1 parent 02a1cd2 commit 85548b8

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
@@ -625,7 +625,6 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data): void
625625
}
626626

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

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

845843
$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
@@ -382,16 +382,21 @@ private function calculateStatistics(): void
382382
unset($tokens);
383383

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

390-
unset($codeUnit);
395+
$this->numExecutableLines++;
396+
}
391397

392-
$this->numExecutableLines++;
393398

394-
if (\count($this->coverageData['lines'][$lineNumber]) > 0) {
399+
if ($this->coverageData['lines'][$lineNumber]['pathCovered'] === true) {
395400
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
396401
$codeUnit['executedLines']++;
397402
}
@@ -477,6 +482,19 @@ private function calcAndApplyClassAggregate(
477482
foreach ($classOrTrait['methods'] as &$method) {
478483
$methodName = $method['methodName'];
479484

485+
if ($method['executableLines'] > 0) {
486+
$method['coverage'] = ($method['executedLines'] / $method['executableLines']) * 100;
487+
} else {
488+
$method['coverage'] = 100;
489+
}
490+
491+
$method['crap'] = $this->crap(
492+
$method['ccn'],
493+
$method['coverage']
494+
);
495+
496+
$classOrTrait['ccn'] += $method['ccn'];
497+
480498
if (isset($this->coverageData['paths'])) {
481499
$methodCoveragePath = $methodName;
482500

@@ -504,19 +522,6 @@ private function calcAndApplyClassAggregate(
504522
$this->numTestedPaths += $numExexutedPaths;
505523
}
506524

507-
if ($method['executableLines'] > 0) {
508-
$method['coverage'] = ($method['executedLines'] /
509-
$method['executableLines']) * 100;
510-
} else {
511-
$method['coverage'] = 100;
512-
}
513-
514-
$method['crap'] = $this->crap(
515-
$method['ccn'],
516-
$method['coverage']
517-
);
518-
519-
$classOrTrait['ccn'] += $method['ccn'];
520525
}
521526

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

0 commit comments

Comments
 (0)