Skip to content

Commit 7e77b6d

Browse files
Narrow types
1 parent ac94671 commit 7e77b6d

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/Report/Xml/Facade.php

+16
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@
3232
use SebastianBergmann\CodeCoverage\Driver\WriteOperationFailedException;
3333
use SebastianBergmann\CodeCoverage\Node\AbstractNode;
3434
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
35+
use SebastianBergmann\CodeCoverage\Node\File;
3536
use SebastianBergmann\CodeCoverage\Node\File as FileNode;
3637
use SebastianBergmann\CodeCoverage\Util\Filesystem as DirectoryUtil;
3738
use SebastianBergmann\CodeCoverage\Version;
3839
use SebastianBergmann\CodeCoverage\XmlException;
3940
use SebastianBergmann\Environment\Runtime;
4041

42+
/**
43+
* @phpstan-import-type ProcessedClassType from File
44+
* @phpstan-import-type ProcessedTraitType from File
45+
* @phpstan-import-type ProcessedFunctionType from File
46+
* @phpstan-import-type TestType from CodeCoverage
47+
*/
4148
final class Facade
4249
{
4350
private string $target;
@@ -175,6 +182,9 @@ private function processFile(FileNode $file, Directory $context): void
175182
$this->saveDocument($fileReport->asDom(), $file->id());
176183
}
177184

185+
/**
186+
* @param ProcessedClassType|ProcessedTraitType $unit
187+
*/
178188
private function processUnit(array $unit, Report $report): void
179189
{
180190
if (isset($unit['className'])) {
@@ -205,6 +215,9 @@ private function processUnit(array $unit, Report $report): void
205215
}
206216
}
207217

218+
/**
219+
* @param ProcessedFunctionType $function
220+
*/
208221
private function processFunction(array $function, Report $report): void
209222
{
210223
$functionObject = $report->functionObject($function['functionName']);
@@ -215,6 +228,9 @@ private function processFunction(array $function, Report $report): void
215228
$functionObject->setTotals((string) $function['executableLines'], (string) $function['executedLines'], (string) $function['coverage']);
216229
}
217230

231+
/**
232+
* @param array<string, TestType> $tests
233+
*/
218234
private function processTests(array $tests): void
219235
{
220236
$testsObject = $this->project->tests();

src/Report/Xml/Report.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function asDom(): DOMDocument
4040
return $this->dom();
4141
}
4242

43-
public function functionObject($name): Method
43+
public function functionObject(string $name): Method
4444
{
4545
$node = $this->contextNode()->appendChild(
4646
$this->dom()->createElementNS(
@@ -54,12 +54,12 @@ public function functionObject($name): Method
5454
return new Method($node, $name);
5555
}
5656

57-
public function classObject($name): Unit
57+
public function classObject(string $name): Unit
5858
{
5959
return $this->unitObject('class', $name);
6060
}
6161

62-
public function traitObject($name): Unit
62+
public function traitObject(string $name): Unit
6363
{
6464
return $this->unitObject('trait', $name);
6565
}
@@ -91,7 +91,7 @@ private function setName(string $name): void
9191
$this->contextNode()->setAttribute('path', dirname($name));
9292
}
9393

94-
private function unitObject(string $tagName, $name): Unit
94+
private function unitObject(string $tagName, string $name): Unit
9595
{
9696
$node = $this->contextNode()->appendChild(
9797
$this->dom()->createElementNS(

src/StaticAnalysis/CachingFileAnalyser.php

+20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
/**
2424
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
2525
*
26+
* @phpstan-type CachedDataForFile array{
27+
* interfacesIn: array<string, Interface_>,
28+
* classesIn: array<string, Class_>,
29+
* traitsIn: array<string, Trait_>,
30+
* functionsIn: array<string, Function_>,
31+
* linesOfCodeFor: LinesOfCode,
32+
* ignoredLinesFor: LinesType,
33+
* executableLinesIn: LinesType
34+
* }
35+
*
2636
* @phpstan-import-type LinesType from FileAnalyser
2737
*/
2838
final class CachingFileAnalyser implements FileAnalyser
@@ -32,6 +42,10 @@ final class CachingFileAnalyser implements FileAnalyser
3242
private readonly FileAnalyser $analyser;
3343
private readonly bool $useAnnotationsForIgnoringCode;
3444
private readonly bool $ignoreDeprecatedCode;
45+
46+
/**
47+
* @var array<non-empty-string, CachedDataForFile>
48+
*/
3549
private array $cache = [];
3650

3751
public function __construct(string $directory, FileAnalyser $analyser, bool $useAnnotationsForIgnoringCode, bool $ignoreDeprecatedCode)
@@ -148,6 +162,9 @@ public function process(string $filename): void
148162
$this->write($filename, $this->cache[$filename]);
149163
}
150164

165+
/**
166+
* @return CachedDataForFile|false
167+
*/
151168
private function read(string $filename): array|false
152169
{
153170
$cacheFile = $this->cacheFile($filename);
@@ -171,6 +188,9 @@ private function read(string $filename): array|false
171188
);
172189
}
173190

191+
/**
192+
* @param CachedDataForFile $data
193+
*/
174194
private function write(string $filename, array $data): void
175195
{
176196
file_put_contents(

src/Target/MapBuilder.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* @phpstan-import-type TargetMap from Mapper
22+
* @phpstan-import-type TargetMapPart from Mapper
2223
*
2324
* @immutable
2425
*
@@ -157,12 +158,13 @@ public function build(Filter $filter, FileAnalyser $analyser): array
157158
}
158159

159160
/**
160-
* @param-out array $data
161-
*
161+
* @param TargetMapPart $data
162162
* @param non-empty-string $unit
163163
* @param non-empty-string $file
164164
* @param positive-int $startLine
165165
* @param positive-int $endLine
166+
*
167+
* @param-out TargetMapPart $data
166168
*/
167169
private function process(array &$data, string $unit, string $file, int $startLine, int $endLine): void
168170
{

0 commit comments

Comments
 (0)