diff --git a/src/Data/ProcessedCodeCoverageData.php b/src/Data/ProcessedCodeCoverageData.php index 976aaab38..49a103236 100644 --- a/src/Data/ProcessedCodeCoverageData.php +++ b/src/Data/ProcessedCodeCoverageData.php @@ -41,6 +41,7 @@ * }> * } * @phpstan-type FunctionCoverageType array> + * @phpstan-type LineCoverageType array>> */ final class ProcessedCodeCoverageData { @@ -48,7 +49,7 @@ final class ProcessedCodeCoverageData * Line coverage data. * An array of filenames, each having an array of linenumbers, each executable line having an array of testcase ids. * - * @var array>> + * @var LineCoverageType */ private array $lineCoverage = []; @@ -111,11 +112,17 @@ public function markCodeAsExecutedByTestCase(string $testCaseId, RawCodeCoverage } } + /** + * @param LineCoverageType $lineCoverage + */ public function setLineCoverage(array $lineCoverage): void { $this->lineCoverage = $lineCoverage; } + /** + * @return LineCoverageType + */ public function lineCoverage(): array { ksort($this->lineCoverage); @@ -123,11 +130,17 @@ public function lineCoverage(): array return $this->lineCoverage; } + /** + * @param FunctionCoverageType $functionCoverage + */ public function setFunctionCoverage(array $functionCoverage): void { $this->functionCoverage = $functionCoverage; } + /** + * @return FunctionCoverageType + */ public function functionCoverage(): array { ksort($this->functionCoverage); @@ -135,6 +148,9 @@ public function functionCoverage(): array return $this->functionCoverage; } + /** + * @return array + */ public function coveredFiles(): array { ksort($this->lineCoverage); diff --git a/src/Node/Builder.php b/src/Node/Builder.php index 19fc3a24d..9a2efe145 100644 --- a/src/Node/Builder.php +++ b/src/Node/Builder.php @@ -140,6 +140,9 @@ private function buildDirectoryStructure(ProcessedCodeCoverageData $data): array { $result = []; + $lineCoverage = $data->lineCoverage(); + $functionCoverage = $data->functionCoverage(); + foreach ($data->coveredFiles() as $originalPath) { $path = explode(DIRECTORY_SEPARATOR, $originalPath); $pointer = &$result; @@ -156,8 +159,8 @@ private function buildDirectoryStructure(ProcessedCodeCoverageData $data): array } $pointer = [ - 'lineCoverage' => $data->lineCoverage()[$originalPath] ?? [], - 'functionCoverage' => $data->functionCoverage()[$originalPath] ?? [], + 'lineCoverage' => $lineCoverage[$originalPath] ?? [], + 'functionCoverage' => $functionCoverage[$originalPath] ?? [], ]; } @@ -203,12 +206,14 @@ private function buildDirectoryStructure(ProcessedCodeCoverageData $data): array */ private function reducePaths(ProcessedCodeCoverageData $coverage): string { - if ($coverage->coveredFiles() === []) { + $coveredFiles = $coverage->coveredFiles(); + + if ($coveredFiles === []) { return '.'; } $commonPath = ''; - $paths = $coverage->coveredFiles(); + $paths = $coveredFiles; if (count($paths) === 1) { $commonPath = dirname($paths[0]) . DIRECTORY_SEPARATOR; @@ -260,7 +265,7 @@ private function reducePaths(ProcessedCodeCoverageData $coverage): string } } - $original = $coverage->coveredFiles(); + $original = $coveredFiles; $max = count($original); for ($i = 0; $i < $max; $i++) {