Skip to content

Commit

Permalink
Narrow types
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 10, 2024
1 parent 6c8fd83 commit 3a34631
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
/**
* Provides collection functionality for PHP code coverage information.
*
* @phpstan-type TestType array{
* size: string,
* status: string,
* }
* @phpstan-type TestType array{size: string, status: string}
* @phpstan-type TargetedLines array<non-empty-string, list<positive-int>>
*/
final class CodeCoverage
{
Expand Down Expand Up @@ -374,6 +372,9 @@ public function validate(TargetCollection $targets): ValidationResult
}

/**
* @param false|TargetedLines $linesToBeCovered
* @param TargetedLines $linesToBeUsed
*
* @throws ReflectionException
* @throws UnintentionallyCoveredCodeException
*/
Expand Down Expand Up @@ -478,6 +479,9 @@ private function addUncoveredFilesFromFilter(): void
}

/**
* @param TargetedLines $linesToBeCovered
* @param TargetedLines $linesToBeUsed
*
* @throws ReflectionException
* @throws UnintentionallyCoveredCodeException
*/
Expand Down Expand Up @@ -507,6 +511,12 @@ private function performUnintentionallyCoveredCodeCheck(RawCodeCoverageData $dat
}
}

/**
* @param TargetedLines $linesToBeCovered
* @param TargetedLines $linesToBeUsed
*
* @return TargetedLines
*/
private function getAllowedLines(array $linesToBeCovered, array $linesToBeUsed): array
{
$allowedLines = [];
Expand Down
3 changes: 3 additions & 0 deletions src/Data/RawCodeCoverageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ private function skipEmptyLines(): void
}
}

/**
* @return array<int>
*/
private function getEmptyLinesForFile(string $filename): array
{
if (!isset(self::$emptyLineCache[$filename])) {
Expand Down
7 changes: 7 additions & 0 deletions src/Node/AbstractNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ abstract class AbstractNode implements Countable
{
private readonly string $name;
private string $pathAsString;

/**
* @var non-empty-list<self>
*/
private array $pathAsArray;
private readonly ?AbstractNode $parent;
private string $id;
Expand Down Expand Up @@ -61,6 +65,9 @@ public function pathAsString(): string
return $this->pathAsString;
}

/**
* @return non-empty-list<self>
*/
public function pathAsArray(): array
{
return $this->pathAsArray;
Expand Down
2 changes: 2 additions & 0 deletions src/Node/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use RecursiveIterator;

/**
* @template-implements RecursiveIterator<int, AbstractNode>
*
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
final class Iterator implements RecursiveIterator
Expand Down

0 comments on commit 3a34631

Please sign in to comment.