diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml
index 63bccd0d8..a212ac9eb 100644
--- a/.psalm/baseline.xml
+++ b/.psalm/baseline.xml
@@ -10,17 +10,28 @@
+
+ $functionData
+ $functionData
+
- functionCoverage[$file][$functionName]['branches'][$branchId]['hit']]]>
+ lineCoverage[$file][$line]]]>
-
- functionCoverage[$file][$functionName]['branches']]]>
- functionCoverage[$file][$functionName]['branches'][$branchId]]]>
- functionCoverage[$file][$functionName]['branches'][$branchId]['hit']]]>
-
-
- functionCoverage[$file][$functionName]['branches']]]>
-
+
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ functionCoverage]]>
+ lineCoverage]]>
+ lineCoverage]]>
+ lineCoverage]]>
+
@@ -67,11 +78,28 @@
-
- codeUnitsByLine]]>
- codeUnitsByLine]]>
- codeUnitsByLine]]>
-
+
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ classes]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+ traits]]>
+
diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php
index 6a8ea970f..094f56142 100644
--- a/src/CodeCoverage.php
+++ b/src/CodeCoverage.php
@@ -35,6 +35,11 @@
/**
* Provides collection functionality for PHP code coverage information.
+ *
+ * @psalm-type TestType = array{
+ * size: string,
+ * status: string,
+ * }
*/
final class CodeCoverage
{
@@ -51,7 +56,7 @@ final class CodeCoverage
private bool $useAnnotationsForIgnoringCode = true;
/**
- * @psalm-var array
+ * @psalm-var array
*/
private array $tests = [];
@@ -120,7 +125,7 @@ public function setData(ProcessedCodeCoverageData $data): void
}
/**
- * @psalm-return array
+ * @psalm-return array
*/
public function getTests(): array
{
@@ -128,7 +133,7 @@ public function getTests(): array
}
/**
- * @psalm-param array $tests
+ * @psalm-param array $tests
*/
public function setTests(array $tests): void
{
diff --git a/src/Data/ProcessedCodeCoverageData.php b/src/Data/ProcessedCodeCoverageData.php
index 49d7acb0b..550c037a2 100644
--- a/src/Data/ProcessedCodeCoverageData.php
+++ b/src/Data/ProcessedCodeCoverageData.php
@@ -20,12 +20,18 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type XdebugFunctionCoverageType from \SebastianBergmann\CodeCoverage\Driver\XdebugDriver
+ *
+ * @psalm-type TestIdType = string
*/
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.
+ *
+ * @psalm-var array>>
*/
private array $lineCoverage = [];
@@ -33,6 +39,23 @@ final class ProcessedCodeCoverageData
* Function coverage data.
* Maintains base format of raw data (@see https://xdebug.org/docs/code_coverage), but each 'hit' entry is an array
* of testcase ids.
+ *
+ * @psalm-var array,
+ * out: array,
+ * out_hit: array,
+ * }>,
+ * paths: array,
+ * hit: list,
+ * }>,
+ * hit: list
+ * }>>
*/
private array $functionCoverage = [];
@@ -213,6 +236,8 @@ private function priorityForLine(array $data, int $line): int
/**
* For a function we have never seen before, copy all data over and simply init the 'hit' array.
+ *
+ * @psalm-param XdebugFunctionCoverageType $functionData
*/
private function initPreviouslyUnseenFunction(string $file, string $functionName, array $functionData): void
{
@@ -231,6 +256,8 @@ private function initPreviouslyUnseenFunction(string $file, string $functionName
* For a function we have seen before, only copy over and init the 'hit' array for any unseen branches and paths.
* Techniques such as mocking and where the contents of a file are different vary during tests (e.g. compiling
* containers) mean that the functions inside a file cannot be relied upon to be static.
+ *
+ * @psalm-param XdebugFunctionCoverageType $functionData
*/
private function initPreviouslySeenFunction(string $file, string $functionName, array $functionData): void
{
diff --git a/src/Data/RawCodeCoverageData.php b/src/Data/RawCodeCoverageData.php
index c261faffd..0d91745f8 100644
--- a/src/Data/RawCodeCoverageData.php
+++ b/src/Data/RawCodeCoverageData.php
@@ -26,6 +26,10 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type XdebugFunctionsCoverageType from \SebastianBergmann\CodeCoverage\Driver\XdebugDriver
+ * @psalm-import-type XdebugCodeCoverageWithoutPathCoverageType from \SebastianBergmann\CodeCoverage\Driver\XdebugDriver
+ * @psalm-import-type XdebugCodeCoverageWithPathCoverageType from \SebastianBergmann\CodeCoverage\Driver\XdebugDriver
*/
final class RawCodeCoverageData
{
@@ -35,20 +39,26 @@ final class RawCodeCoverageData
private static array $emptyLineCache = [];
/**
- * @see https://xdebug.org/docs/code_coverage for format
+ * @psalm-var XdebugCodeCoverageWithoutPathCoverageType
*/
private array $lineCoverage;
/**
- * @see https://xdebug.org/docs/code_coverage for format
+ * @psalm-var array
*/
private array $functionCoverage;
+ /**
+ * @psalm-param XdebugCodeCoverageWithoutPathCoverageType $rawCoverage
+ */
public static function fromXdebugWithoutPathCoverage(array $rawCoverage): self
{
return new self($rawCoverage, []);
}
+ /**
+ * @psalm-param XdebugCodeCoverageWithPathCoverageType $rawCoverage
+ */
public static function fromXdebugWithPathCoverage(array $rawCoverage): self
{
$lineCoverage = [];
@@ -73,6 +83,10 @@ public static function fromUncoveredFile(string $filename, FileAnalyser $analyse
return new self([$filename => $lineCoverage], []);
}
+ /**
+ * @psalm-param XdebugCodeCoverageWithoutPathCoverageType $lineCoverage
+ * @psalm-param array $functionCoverage
+ */
private function __construct(array $lineCoverage, array $functionCoverage)
{
$this->lineCoverage = $lineCoverage;
@@ -86,11 +100,17 @@ public function clear(): void
$this->lineCoverage = $this->functionCoverage = [];
}
+ /**
+ * @psalm-return XdebugCodeCoverageWithoutPathCoverageType
+ */
public function lineCoverage(): array
{
return $this->lineCoverage;
}
+ /**
+ * @psalm-return array
+ */
public function functionCoverage(): array
{
return $this->functionCoverage;
diff --git a/src/Driver/XdebugDriver.php b/src/Driver/XdebugDriver.php
index 3a06c11fc..3123de6eb 100644
--- a/src/Driver/XdebugDriver.php
+++ b/src/Driver/XdebugDriver.php
@@ -31,6 +31,34 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @see https://xdebug.org/docs/code_coverage#xdebug_get_code_coverage
+ *
+ * @psalm-type XdebugLinesCoverageType = array
+ * @psalm-type XdebugBranchCoverageType = array{
+ * op_start: int,
+ * op_end: int,
+ * line_start: int,
+ * line_end: int,
+ * hit: int,
+ * out: array,
+ * out_hit: array,
+ * }
+ * @psalm-type XdebugPathCoverageType = array{
+ * path: array,
+ * hit: int,
+ * }
+ * @psalm-type XdebugFunctionCoverageType = array{
+ * branches: array,
+ * paths: array,
+ * }
+ * @psalm-type XdebugFunctionsCoverageType = array
+ * @psalm-type XdebugPathAndBranchesCoverageType = array{
+ * lines: XdebugLinesCoverageType,
+ * functions: XdebugFunctionsCoverageType,
+ * }
+ * @psalm-type XdebugCodeCoverageWithoutPathCoverageType = array
+ * @psalm-type XdebugCodeCoverageWithPathCoverageType = array
*/
final class XdebugDriver extends Driver
{
@@ -84,9 +112,11 @@ public function stop(): RawCodeCoverageData
xdebug_stop_code_coverage();
if ($this->collectsBranchAndPathCoverage()) {
+ /* @var XdebugCodeCoverageWithPathCoverageType $data */
return RawCodeCoverageData::fromXdebugWithPathCoverage($data);
}
+ /* @var XdebugCodeCoverageWithoutPathCoverageType $data */
return RawCodeCoverageData::fromXdebugWithoutPathCoverage($data);
}
diff --git a/src/Node/AbstractNode.php b/src/Node/AbstractNode.php
index a53d6e883..214258e78 100644
--- a/src/Node/AbstractNode.php
+++ b/src/Node/AbstractNode.php
@@ -19,6 +19,11 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type LinesOfCodeType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
+ * @psalm-import-type ProcessedFunctionType from \SebastianBergmann\CodeCoverage\Node\File
+ * @psalm-import-type ProcessedClassType from \SebastianBergmann\CodeCoverage\Node\File
+ * @psalm-import-type ProcessedTraitType from \SebastianBergmann\CodeCoverage\Node\File
*/
abstract class AbstractNode implements Countable
{
@@ -163,14 +168,23 @@ public function numberOfTestedFunctionsAndMethods(): int
return $this->numberOfTestedFunctions() + $this->numberOfTestedMethods();
}
+ /**
+ * @psalm-return array
+ */
abstract public function classes(): array;
+ /**
+ * @psalm-return array
+ */
abstract public function traits(): array;
+ /**
+ * @psalm-return array
+ */
abstract public function functions(): array;
/**
- * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
+ * @psalm-return LinesOfCodeType
*/
abstract public function linesOfCode(): array;
diff --git a/src/Node/Builder.php b/src/Node/Builder.php
index f5edda89c..a2885752b 100644
--- a/src/Node/Builder.php
+++ b/src/Node/Builder.php
@@ -27,6 +27,8 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type TestType from \SebastianBergmann\CodeCoverage\CodeCoverage
*/
final class Builder
{
@@ -56,7 +58,7 @@ public function build(CodeCoverage $coverage): Directory
}
/**
- * @psalm-param array $tests
+ * @psalm-param array $tests
*/
private function addItems(Directory $root, array $items, array $tests): void
{
@@ -129,6 +131,8 @@ private function addItems(Directory $root, array $items, array $tests): void
* )
* )
*
+ *
+ * @psalm-return array, functionCoverage: array>}>>
*/
private function buildDirectoryStructure(ProcessedCodeCoverageData $data): array
{
diff --git a/src/Node/Directory.php b/src/Node/Directory.php
index 0e4302649..8e71f6460 100644
--- a/src/Node/Directory.php
+++ b/src/Node/Directory.php
@@ -16,6 +16,8 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type LinesOfCodeType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
*/
final class Directory extends AbstractNode implements IteratorAggregate
{
@@ -38,7 +40,7 @@ final class Directory extends AbstractNode implements IteratorAggregate
private ?array $functions = null;
/**
- * @psalm-var null|array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
+ * @psalm-var null|LinesOfCodeType
*/
private ?array $linesOfCode = null;
private int $numFiles = -1;
@@ -161,7 +163,7 @@ public function functions(): array
}
/**
- * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
+ * @psalm-return LinesOfCodeType
*/
public function linesOfCode(): array
{
diff --git a/src/Node/File.php b/src/Node/File.php
index ecc6aaaf7..04b301d8e 100644
--- a/src/Node/File.php
+++ b/src/Node/File.php
@@ -15,6 +15,80 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type CodeUnitFunctionType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitMethodType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitClassType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitTraitType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type LinesOfCodeType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
+ * @psalm-import-type LinesType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
+ *
+ * @psalm-type ProcessedFunctionType = array{
+ * functionName: string,
+ * namespace: string,
+ * signature: string,
+ * startLine: int,
+ * endLine: int,
+ * executableLines: int,
+ * executedLines: int,
+ * executableBranches: int,
+ * executedBranches: int,
+ * executablePaths: int,
+ * executedPaths: int,
+ * ccn: int,
+ * coverage: int|float,
+ * crap: int|string,
+ * link: string
+ * }
+ * @psalm-type ProcessedMethodType = array{
+ * methodName: string,
+ * visibility: string,
+ * signature: string,
+ * startLine: int,
+ * endLine: int,
+ * executableLines: int,
+ * executedLines: int,
+ * executableBranches: int,
+ * executedBranches: int,
+ * executablePaths: int,
+ * executedPaths: int,
+ * ccn: int,
+ * coverage: float|int,
+ * crap: int|string,
+ * link: string
+ * }
+ * @psalm-type ProcessedClassType = array{
+ * className: string,
+ * namespace: string,
+ * methods: array,
+ * startLine: int,
+ * executableLines: int,
+ * executedLines: int,
+ * executableBranches: int,
+ * executedBranches: int,
+ * executablePaths: int,
+ * executedPaths: int,
+ * ccn: int,
+ * coverage: int|float,
+ * crap: int|string,
+ * link: string
+ * }
+ * @psalm-type ProcessedTraitType = array{
+ * traitName: string,
+ * namespace: string,
+ * methods: array,
+ * startLine: int,
+ * executableLines: int,
+ * executedLines: int,
+ * executableBranches: int,
+ * executedBranches: int,
+ * executablePaths: int,
+ * executedPaths: int,
+ * ccn: int,
+ * coverage: float|int,
+ * crap: int|string,
+ * link: string
+ * }
*/
final class File extends AbstractNode
{
@@ -27,12 +101,24 @@ final class File extends AbstractNode
private int $numExecutedBranches = 0;
private int $numExecutablePaths = 0;
private int $numExecutedPaths = 0;
- private array $classes = [];
- private array $traits = [];
- private array $functions = [];
/**
- * @psalm-var array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
+ * @psalm-var array
+ */
+ private array $classes = [];
+
+ /**
+ * @psalm-var array
+ */
+ private array $traits = [];
+
+ /**
+ * @psalm-var array
+ */
+ private array $functions = [];
+
+ /**
+ * @psalm-var LinesOfCodeType
*/
private readonly array $linesOfCode;
private ?int $numClasses = null;
@@ -42,10 +128,17 @@ final class File extends AbstractNode
private ?int $numMethods = null;
private ?int $numTestedMethods = null;
private ?int $numTestedFunctions = null;
- private array $codeUnitsByLine = [];
/**
- * @psalm-param array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int} $linesOfCode
+ * @var array
+ */
+ private array $codeUnitsByLine = [];
+
+ /**
+ * @psalm-param LinesOfCodeType $linesOfCode
+ * @psalm-param array $classes
+ * @psalm-param array $traits
+ * @psalm-param array $functions
*/
public function __construct(string $name, AbstractNode $parent, array $lineCoverageData, array $functionCoverageData, array $testData, array $classes, array $traits, array $functions, array $linesOfCode)
{
@@ -94,9 +187,6 @@ public function functions(): array
return $this->functions;
}
- /**
- * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
- */
public function linesOfCode(): array
{
return $this->linesOfCode;
@@ -253,6 +343,11 @@ public function numberOfTestedFunctions(): int
return $this->numTestedFunctions;
}
+ /**
+ * @psalm-param array $classes
+ * @psalm-param array $traits
+ * @psalm-param array $functions
+ */
private function calculateStatistics(array $classes, array $traits, array $functions): void
{
foreach (range(1, $this->linesOfCode['linesOfCode']) as $lineNumber) {
@@ -355,6 +450,9 @@ private function calculateStatistics(array $classes, array $traits, array $funct
}
}
+ /**
+ * @psalm-param array $classes
+ */
private function processClasses(array $classes): void
{
$link = $this->id() . '.html#';
@@ -401,6 +499,9 @@ private function processClasses(array $classes): void
}
}
+ /**
+ * @psalm-param array $traits
+ */
private function processTraits(array $traits): void
{
$link = $this->id() . '.html#';
@@ -447,6 +548,9 @@ private function processTraits(array $traits): void
}
}
+ /**
+ * @psalm-param array $functions
+ */
private function processFunctions(array $functions): void
{
$link = $this->id() . '.html#';
@@ -513,6 +617,11 @@ static function (array $path)
}
}
+ /**
+ * @psalm-param CodeUnitMethodType $method
+ *
+ * @psalm-return ProcessedMethodType
+ */
private function newMethod(string $className, string $methodName, array $method, string $link): array
{
$methodData = [
diff --git a/src/Report/Xml/Tests.php b/src/Report/Xml/Tests.php
index b40610495..e56df70e6 100644
--- a/src/Report/Xml/Tests.php
+++ b/src/Report/Xml/Tests.php
@@ -13,6 +13,8 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type TestType from \SebastianBergmann\CodeCoverage\CodeCoverage
*/
final class Tests
{
@@ -23,6 +25,9 @@ public function __construct(DOMElement $context)
$this->contextNode = $context;
}
+ /**
+ * @param TestType $result
+ */
public function addTest(string $test, array $result): void
{
$node = $this->contextNode->appendChild(
diff --git a/src/StaticAnalysis/CachingFileAnalyser.php b/src/StaticAnalysis/CachingFileAnalyser.php
index 511a9fa42..3f20f970d 100644
--- a/src/StaticAnalysis/CachingFileAnalyser.php
+++ b/src/StaticAnalysis/CachingFileAnalyser.php
@@ -21,6 +21,8 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type LinesOfCodeType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
*/
final class CachingFileAnalyser implements FileAnalyser
{
@@ -65,7 +67,7 @@ public function functionsIn(string $filename): array
}
/**
- * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
+ * @psalm-return LinesOfCodeType
*/
public function linesOfCodeFor(string $filename): array
{
diff --git a/src/StaticAnalysis/CodeUnitFindingVisitor.php b/src/StaticAnalysis/CodeUnitFindingVisitor.php
index 019b70b5a..265c151e6 100644
--- a/src/StaticAnalysis/CodeUnitFindingVisitor.php
+++ b/src/StaticAnalysis/CodeUnitFindingVisitor.php
@@ -32,21 +32,55 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-type CodeUnitFunctionType = array{
+ * name: string,
+ * namespacedName: string,
+ * namespace: string,
+ * signature: string,
+ * startLine: int,
+ * endLine: int,
+ * ccn: int
+ * }
+ * @psalm-type CodeUnitMethodType = array{
+ * methodName: string,
+ * signature: string,
+ * visibility: string,
+ * startLine: int,
+ * endLine: int,
+ * ccn: int
+ * }
+ * @psalm-type CodeUnitClassType = array{
+ * name: string,
+ * namespacedName: string,
+ * namespace: string,
+ * startLine: int,
+ * endLine: int,
+ * methods: array
+ * }
+ * @psalm-type CodeUnitTraitType = array{
+ * name: string,
+ * namespacedName: string,
+ * namespace: string,
+ * startLine: int,
+ * endLine: int,
+ * methods: array
+ * }
*/
final class CodeUnitFindingVisitor extends NodeVisitorAbstract
{
/**
- * @psalm-var array}>
+ * @psalm-var array
*/
private array $classes = [];
/**
- * @psalm-var array}>
+ * @psalm-var array
*/
private array $traits = [];
/**
- * @psalm-var array
+ * @psalm-var array
*/
private array $functions = [];
@@ -84,7 +118,7 @@ public function enterNode(Node $node): void
}
/**
- * @psalm-return array}>
+ * @psalm-return array
*/
public function classes(): array
{
@@ -92,7 +126,7 @@ public function classes(): array
}
/**
- * @psalm-return array}>
+ * @psalm-return array
*/
public function traits(): array
{
@@ -100,7 +134,7 @@ public function traits(): array
}
/**
- * @psalm-return array
+ * @psalm-return array
*/
public function functions(): array
{
diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php
index 2dbddd8d3..38db49881 100644
--- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php
+++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php
@@ -26,6 +26,8 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type LinesType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
*/
final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
{
@@ -33,7 +35,7 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
private readonly string $source;
/**
- * @psalm-var array
+ * @psalm-var LinesType
*/
private array $executableLinesGroupedByBranch = [];
@@ -352,6 +354,9 @@ public function afterTraverse(array $nodes): void
);
}
+ /**
+ * @psalm-return LinesType
+ */
public function executableLinesGroupedByBranch(): array
{
return $this->executableLinesGroupedByBranch;
diff --git a/src/StaticAnalysis/FileAnalyser.php b/src/StaticAnalysis/FileAnalyser.php
index 3dbcf68f6..f260341b1 100644
--- a/src/StaticAnalysis/FileAnalyser.php
+++ b/src/StaticAnalysis/FileAnalyser.php
@@ -11,21 +11,50 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type CodeUnitFunctionType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitMethodType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitClassType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitTraitType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type LinesOfCodeType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
+ * @psalm-import-type LinesType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
+ *
+ * @psalm-type LinesOfCodeType = array{
+ * linesOfCode: int,
+ * commentLinesOfCode: int,
+ * nonCommentLinesOfCode: int
+ * }
+ * @psalm-type LinesType = array
*/
interface FileAnalyser
{
+ /**
+ * @psalm-return array
+ */
public function classesIn(string $filename): array;
+ /**
+ * @psalm-return array
+ */
public function traitsIn(string $filename): array;
+ /**
+ * @psalm-return array
+ */
public function functionsIn(string $filename): array;
/**
- * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
+ * @psalm-return LinesOfCodeType
*/
public function linesOfCodeFor(string $filename): array;
+ /**
+ * @psalm-return LinesType
+ */
public function executableLinesIn(string $filename): array;
+ /**
+ * @psalm-return LinesType
+ */
public function ignoredLinesFor(string $filename): array;
}
diff --git a/src/StaticAnalysis/ParsingFileAnalyser.php b/src/StaticAnalysis/ParsingFileAnalyser.php
index dec907b77..0fa491a67 100644
--- a/src/StaticAnalysis/ParsingFileAnalyser.php
+++ b/src/StaticAnalysis/ParsingFileAnalyser.php
@@ -32,18 +32,44 @@
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
+ *
+ * @psalm-import-type CodeUnitFunctionType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitMethodType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitClassType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type CodeUnitTraitType from \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
+ * @psalm-import-type LinesOfCodeType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
+ * @psalm-import-type LinesType from \SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser
*/
final class ParsingFileAnalyser implements FileAnalyser
{
- private array $classes = [];
- private array $traits = [];
+ /**
+ * @psalm-var array>
+ */
+ private array $classes = [];
+
+ /**
+ * @psalm-var array>
+ */
+ private array $traits = [];
+
+ /**
+ * @psalm-var array>
+ */
private array $functions = [];
/**
- * @var array
+ * @var array
+ */
+ private array $linesOfCode = [];
+
+ /**
+ * @var array
+ */
+ private array $ignoredLines = [];
+
+ /**
+ * @var array
*/
- private array $linesOfCode = [];
- private array $ignoredLines = [];
private array $executableLines = [];
private readonly bool $useAnnotationsForIgnoringCode;
private readonly bool $ignoreDeprecatedCode;
@@ -75,9 +101,6 @@ public function functionsIn(string $filename): array
return $this->functions[$filename];
}
- /**
- * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
- */
public function linesOfCodeFor(string $filename): array
{
$this->analyse($filename);