From 3a34631adc72ee7f627247a46d52622e6a77c5c5 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 10 Dec 2024 08:15:05 +0100 Subject: [PATCH] Narrow types --- src/CodeCoverage.php | 18 ++++++++++++++---- src/Data/RawCodeCoverageData.php | 3 +++ src/Node/AbstractNode.php | 7 +++++++ src/Node/Iterator.php | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 1d4cacf1..3b4aff15 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -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> */ final class CodeCoverage { @@ -374,6 +372,9 @@ public function validate(TargetCollection $targets): ValidationResult } /** + * @param false|TargetedLines $linesToBeCovered + * @param TargetedLines $linesToBeUsed + * * @throws ReflectionException * @throws UnintentionallyCoveredCodeException */ @@ -478,6 +479,9 @@ private function addUncoveredFilesFromFilter(): void } /** + * @param TargetedLines $linesToBeCovered + * @param TargetedLines $linesToBeUsed + * * @throws ReflectionException * @throws UnintentionallyCoveredCodeException */ @@ -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 = []; diff --git a/src/Data/RawCodeCoverageData.php b/src/Data/RawCodeCoverageData.php index 81acc86f..058ec199 100644 --- a/src/Data/RawCodeCoverageData.php +++ b/src/Data/RawCodeCoverageData.php @@ -261,6 +261,9 @@ private function skipEmptyLines(): void } } + /** + * @return array + */ private function getEmptyLinesForFile(string $filename): array { if (!isset(self::$emptyLineCache[$filename])) { diff --git a/src/Node/AbstractNode.php b/src/Node/AbstractNode.php index 396e888f..2cee547f 100644 --- a/src/Node/AbstractNode.php +++ b/src/Node/AbstractNode.php @@ -29,6 +29,10 @@ abstract class AbstractNode implements Countable { private readonly string $name; private string $pathAsString; + + /** + * @var non-empty-list + */ private array $pathAsArray; private readonly ?AbstractNode $parent; private string $id; @@ -61,6 +65,9 @@ public function pathAsString(): string return $this->pathAsString; } + /** + * @return non-empty-list + */ public function pathAsArray(): array { return $this->pathAsArray; diff --git a/src/Node/Iterator.php b/src/Node/Iterator.php index 3031bf74..ab3c8eb9 100644 --- a/src/Node/Iterator.php +++ b/src/Node/Iterator.php @@ -14,6 +14,8 @@ use RecursiveIterator; /** + * @template-implements RecursiveIterator + * * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage */ final class Iterator implements RecursiveIterator