2929use SebastianBergmann \CodeCoverage \StaticAnalysis \CachingFileAnalyser ;
3030use SebastianBergmann \CodeCoverage \StaticAnalysis \FileAnalyser ;
3131use SebastianBergmann \CodeCoverage \StaticAnalysis \ParsingFileAnalyser ;
32+ use SebastianBergmann \CodeCoverage \Test \Target \MapBuilder ;
33+ use SebastianBergmann \CodeCoverage \Test \Target \Mapper ;
34+ use SebastianBergmann \CodeCoverage \Test \Target \TargetCollection ;
35+ use SebastianBergmann \CodeCoverage \Test \Target \ValidationResult ;
3236use SebastianBergmann \CodeCoverage \Test \TestSize \TestSize ;
3337use SebastianBergmann \CodeCoverage \Test \TestStatus \TestStatus ;
3438use SebastianBergmann \CodeUnitReverseLookup \Wizard ;
@@ -47,6 +51,7 @@ final class CodeCoverage
4751 private readonly Driver $ driver ;
4852 private readonly Filter $ filter ;
4953 private readonly Wizard $ wizard ;
54+ private ?Mapper $ targetMapper = null ;
5055 private bool $ checkForUnintentionallyCoveredCode = false ;
5156 private bool $ ignoreDeprecatedCode = false ;
5257 private ?string $ currentId = null ;
@@ -348,6 +353,11 @@ public function detectsDeadCode(): bool
348353 return $ this ->driver ->detectsDeadCode ();
349354 }
350355
356+ public function validate (TargetCollection $ targets ): ValidationResult
357+ {
358+ return $ targets ->validate ($ this ->targetMapper ());
359+ }
360+
351361 /**
352362 * @throws ReflectionException
353363 * @throws UnintentionallyCoveredCodeException
@@ -566,6 +576,19 @@ private function processUnintentionallyCoveredUnits(array $unintentionallyCovere
566576 return $ processed ;
567577 }
568578
579+ private function targetMapper (): Mapper
580+ {
581+ if ($ this ->targetMapper !== null ) {
582+ return $ this ->targetMapper ;
583+ }
584+
585+ $ this ->targetMapper = new Mapper (
586+ (new MapBuilder )->build ($ this ->filter , $ this ->analyser ()),
587+ );
588+
589+ return $ this ->targetMapper ;
590+ }
591+
569592 private function analyser (): FileAnalyser
570593 {
571594 if ($ this ->analyser !== null ) {
0 commit comments