Skip to content

Commit 7e91099

Browse files
dvdougsebastianbergmann
authored andcommittedAug 24, 2020
Remove preloading when using processUncoveredFiles
As discussed in #799, this feature is no longer required because of Xdebug's built in filter
1 parent a95e4c1 commit 7e91099

File tree

1 file changed

+28
-47
lines changed

1 file changed

+28
-47
lines changed
 

‎src/CodeCoverage.php

+28-47
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use function explode;
2121
use function file_exists;
2222
use function get_class;
23+
use function in_array;
2324
use function is_array;
2425
use function sort;
2526
use PHPUnit\Framework\TestCase;
@@ -108,13 +109,6 @@ final class CodeCoverage
108109
*/
109110
private $parentClassesExcludedFromUnintentionallyCoveredCodeCheck = [];
110111

111-
/**
112-
* Determine if the data has been initialized or not.
113-
*
114-
* @var bool
115-
*/
116-
private $isInitialized = false;
117-
118112
/**
119113
* @var ?CoveredFileAnalyser
120114
*/
@@ -151,10 +145,9 @@ public function getReport(): Directory
151145
*/
152146
public function clear(): void
153147
{
154-
$this->isInitialized = false;
155-
$this->currentId = null;
156-
$this->data = new ProcessedCodeCoverageData;
157-
$this->tests = [];
148+
$this->currentId = null;
149+
$this->data = new ProcessedCodeCoverageData;
150+
$this->tests = [];
158151
}
159152

160153
/**
@@ -170,8 +163,12 @@ public function filter(): Filter
170163
*/
171164
public function getData(bool $raw = false): ProcessedCodeCoverageData
172165
{
173-
if (!$raw && $this->includeUncoveredFiles) {
174-
$this->addUncoveredFilesFromFilter();
166+
if (!$raw) {
167+
if ($this->processUncoveredFiles) {
168+
$this->processUncoveredFilesFromFilter();
169+
} elseif ($this->includeUncoveredFiles) {
170+
$this->addUncoveredFilesFromFilter();
171+
}
175172
}
176173

177174
return $this->data;
@@ -212,10 +209,6 @@ public function start($id, bool $clear = false): void
212209
$this->clear();
213210
}
214211

215-
if ($this->isInitialized === false) {
216-
$this->initializeData();
217-
}
218-
219212
$this->currentId = $id;
220213

221214
$this->driver->start();
@@ -526,6 +519,24 @@ private function addUncoveredFilesFromFilter(): void
526519
}
527520
}
528521

522+
/**
523+
* @throws UnintentionallyCoveredCodeException
524+
*/
525+
private function processUncoveredFilesFromFilter(): void
526+
{
527+
$coveredFiles = $this->data->coveredFiles();
528+
529+
$this->driver->start();
530+
531+
foreach ($this->filter->files() as $file) {
532+
if (!in_array($file, $coveredFiles, true) && $this->filter->isFile($file)) {
533+
include_once $file;
534+
}
535+
}
536+
537+
$this->append($this->driver->stop(), self::UNCOVERED_FILES);
538+
}
539+
529540
/**
530541
* @throws UnintentionallyCoveredCodeException
531542
* @throws ReflectionException
@@ -628,36 +639,6 @@ private function processUnintentionallyCoveredUnits(array $unintentionallyCovere
628639
return array_values($unintentionallyCoveredUnits);
629640
}
630641

631-
/**
632-
* @throws UnintentionallyCoveredCodeException
633-
*/
634-
private function initializeData(): void
635-
{
636-
$this->isInitialized = true;
637-
638-
if ($this->processUncoveredFiles) {
639-
// by collecting dead code data here on an initial pass, future runs with test data do not need to
640-
if ($this->driver->canDetectDeadCode()) {
641-
$this->driver->enableDeadCodeDetection();
642-
}
643-
644-
$this->driver->start();
645-
646-
foreach ($this->filter->files() as $file) {
647-
if ($this->filter->isFile($file)) {
648-
include_once $file;
649-
}
650-
}
651-
652-
// having now collected dead code for the entire list of files, we can safely skip this data on subsequent runs
653-
if ($this->driver->canDetectDeadCode()) {
654-
$this->driver->disableDeadCodeDetection();
655-
}
656-
657-
$this->append($this->driver->stop(), self::UNCOVERED_FILES);
658-
}
659-
}
660-
661642
private function coveredFileAnalyser(): CoveredFileAnalyser
662643
{
663644
if ($this->coveredFileAnalyser !== null) {

0 commit comments

Comments
 (0)
Please sign in to comment.