Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Data/ProcessedCodeCoverageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
* }>
* }
* @phpstan-type FunctionCoverageType array<string, array<string, FunctionCoverageDataType>>
* @phpstan-type LineCoverageType array<string, array<int, null|list<TestIdType>>>
*/
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<string, array<int, null|list<TestIdType>>>
* @var LineCoverageType
*/
private array $lineCoverage = [];

Expand Down Expand Up @@ -111,30 +112,45 @@ 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);

return $this->lineCoverage;
}

/**
* @param FunctionCoverageType $functionCoverage
*/
public function setFunctionCoverage(array $functionCoverage): void
{
$this->functionCoverage = $functionCoverage;
}

/**
* @return FunctionCoverageType
*/
public function functionCoverage(): array
{
ksort($this->functionCoverage);

return $this->functionCoverage;
}

/**
* @return array<string>
*/
public function coveredFiles(): array
{
ksort($this->lineCoverage);
Expand Down
15 changes: 10 additions & 5 deletions src/Node/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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] ?? [],
];
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -260,7 +265,7 @@ private function reducePaths(ProcessedCodeCoverageData $coverage): string
}
}

$original = $coverage->coveredFiles();
$original = $coveredFiles;
$max = count($original);

for ($i = 0; $i < $max; $i++) {
Expand Down