@@ -108,13 +108,6 @@ final class CodeCoverage
108108 */
109109 private $ parentClassesExcludedFromUnintentionallyCoveredCodeCheck = [];
110110
111- /**
112- * Determine if the data has been initialized or not.
113- *
114- * @var bool
115- */
116- private $ isInitialized = false ;
117-
118111 /**
119112 * @var ?CoveredFileAnalyser
120113 */
@@ -151,10 +144,9 @@ public function getReport(): Directory
151144 */
152145 public function clear (): void
153146 {
154- $ this ->isInitialized = false ;
155- $ this ->currentId = null ;
156- $ this ->data = new ProcessedCodeCoverageData ;
157- $ this ->tests = [];
147+ $ this ->currentId = null ;
148+ $ this ->data = new ProcessedCodeCoverageData ;
149+ $ this ->tests = [];
158150 }
159151
160152 /**
@@ -170,8 +162,12 @@ public function filter(): Filter
170162 */
171163 public function getData (bool $ raw = false ): ProcessedCodeCoverageData
172164 {
173- if (!$ raw && $ this ->includeUncoveredFiles ) {
174- $ this ->addUncoveredFilesFromFilter ();
165+ if (!$ raw ) {
166+ if ($ this ->processUncoveredFiles ) {
167+ $ this ->processUncoveredFilesFromFilter ();
168+ } elseif ($ this ->includeUncoveredFiles ) {
169+ $ this ->addUncoveredFilesFromFilter ();
170+ }
175171 }
176172
177173 return $ this ->data ;
@@ -212,10 +208,6 @@ public function start($id, bool $clear = false): void
212208 $ this ->clear ();
213209 }
214210
215- if ($ this ->isInitialized === false ) {
216- $ this ->initializeData ();
217- }
218-
219211 $ this ->currentId = $ id ;
220212
221213 $ this ->driver ->start ();
@@ -510,7 +502,7 @@ private function addUncoveredFilesFromFilter(): void
510502 {
511503 $ uncoveredFiles = array_diff (
512504 $ this ->filter ->files (),
513- array_keys ( $ this ->data ->lineCoverage () )
505+ $ this ->data ->coveredFiles ( )
514506 );
515507
516508 foreach ($ uncoveredFiles as $ uncoveredFile ) {
@@ -526,6 +518,27 @@ private function addUncoveredFilesFromFilter(): void
526518 }
527519 }
528520
521+ /**
522+ * @throws UnintentionallyCoveredCodeException
523+ */
524+ private function processUncoveredFilesFromFilter (): void
525+ {
526+ $ uncoveredFiles = array_diff (
527+ $ this ->filter ->files (),
528+ $ this ->data ->coveredFiles ()
529+ );
530+
531+ $ this ->driver ->start ();
532+
533+ foreach ($ uncoveredFiles as $ uncoveredFile ) {
534+ if (file_exists ($ uncoveredFile )) {
535+ include_once $ uncoveredFile ;
536+ }
537+ }
538+
539+ $ this ->append ($ this ->driver ->stop (), self ::UNCOVERED_FILES );
540+ }
541+
529542 /**
530543 * @throws UnintentionallyCoveredCodeException
531544 * @throws ReflectionException
@@ -628,36 +641,6 @@ private function processUnintentionallyCoveredUnits(array $unintentionallyCovere
628641 return array_values ($ unintentionallyCoveredUnits );
629642 }
630643
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-
661644 private function coveredFileAnalyser (): CoveredFileAnalyser
662645 {
663646 if ($ this ->coveredFileAnalyser !== null ) {
0 commit comments