Skip to content

Commit 9af5908

Browse files
Use lazy initialization
1 parent fc3692c commit 9af5908

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/CodeCoverage.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ public function __construct(Driver $driver = null, Filter $filter = null)
145145
$this->driver = $driver;
146146
$this->filter = $filter;
147147

148-
$this->wizard = new Wizard;
149-
$this->data = new ProcessedCodeCoverageData;
148+
$this->data = new ProcessedCodeCoverageData;
150149
}
151150

152151
/**
@@ -647,7 +646,7 @@ private function performUnintentionallyCoveredCodeCheck(RawCodeCoverageData $dat
647646
foreach ($data->lineCoverage() as $file => $_data) {
648647
foreach ($_data as $line => $flag) {
649648
if ($flag === 1 && !isset($allowedLines[$file][$line])) {
650-
$unintentionallyCoveredUnits[] = $this->wizard->lookup($file, $line);
649+
$unintentionallyCoveredUnits[] = $this->wizard()->lookup($file, $line);
651650
}
652651
}
653652
}
@@ -816,7 +815,7 @@ private function coverageToCodeUnits(RawCodeCoverageData $rawData): array
816815
foreach ($rawData->lineCoverage() as $filename => $lines) {
817816
foreach ($lines as $line => $flag) {
818817
if ($flag === 1) {
819-
$codeUnits[] = $this->wizard->lookup($filename, $line);
818+
$codeUnits[] = $this->wizard()->lookup($filename, $line);
820819
}
821820
}
822821
}
@@ -830,10 +829,19 @@ private function linesToCodeUnits(array $data): array
830829

831830
foreach ($data as $filename => $lines) {
832831
foreach ($lines as $line) {
833-
$codeUnits[] = $this->wizard->lookup($filename, $line);
832+
$codeUnits[] = $this->wizard()->lookup($filename, $line);
834833
}
835834
}
836835

837836
return \array_unique($codeUnits);
838837
}
838+
839+
private function wizard(): Wizard
840+
{
841+
if ($this->wizard === null) {
842+
$this->wizard = new Wizard;
843+
}
844+
845+
return $this->wizard;
846+
}
839847
}

0 commit comments

Comments
 (0)