Skip to content

Commit e1d9411

Browse files
Do not ignore errors reported by PHPStan
1 parent 1ad8a2d commit e1d9411

File tree

4 files changed

+47
-87
lines changed

4 files changed

+47
-87
lines changed

phpstan.neon

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,3 @@ parameters:
44
- src
55
- tests/tests
66
- tests/bootstrap.php
7-
ignoreErrors:
8-
-
9-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\CodeUnitFindingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
10-
count: 1
11-
path: src/StaticAnalysis/CodeUnitFindingVisitor.php
12-
13-
-
14-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\CodeUnitFindingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
15-
count: 1
16-
path: src/StaticAnalysis/CodeUnitFindingVisitor.php
17-
18-
-
19-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\ExecutableLinesFindingVisitor\\:\\:afterTraverse\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:afterTraverse\\(\\)$#"
20-
count: 1
21-
path: src/StaticAnalysis/ExecutableLinesFindingVisitor.php
22-
23-
-
24-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\ExecutableLinesFindingVisitor\\:\\:afterTraverse\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:afterTraverse\\(\\)$#"
25-
count: 1
26-
path: src/StaticAnalysis/ExecutableLinesFindingVisitor.php
27-
28-
-
29-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\ExecutableLinesFindingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
30-
count: 1
31-
path: src/StaticAnalysis/ExecutableLinesFindingVisitor.php
32-
33-
-
34-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\ExecutableLinesFindingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
35-
count: 1
36-
path: src/StaticAnalysis/ExecutableLinesFindingVisitor.php
37-
38-
-
39-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\IgnoredLinesFindingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
40-
count: 1
41-
path: src/StaticAnalysis/IgnoredLinesFindingVisitor.php
42-
43-
-
44-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\IgnoredLinesFindingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
45-
count: 1
46-
path: src/StaticAnalysis/IgnoredLinesFindingVisitor.php
47-
48-
-
49-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\CodeUnitFindingVisitor\\:\\:leaveNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:leaveNode\\(\\)$#"
50-
count: 1
51-
path: src/StaticAnalysis/CodeUnitFindingVisitor.php
52-
53-
-
54-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\CodeCoverage\\\\StaticAnalysis\\\\CodeUnitFindingVisitor\\:\\:leaveNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:leaveNode\\(\\)$#"
55-
count: 1
56-
path: src/StaticAnalysis/CodeUnitFindingVisitor.php

src/StaticAnalysis/CodeUnitFindingVisitor.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ public function __construct(string $file)
6767
$this->file = $file;
6868
}
6969

70-
public function enterNode(Node $node): void
70+
public function enterNode(Node $node): null
7171
{
7272
if ($node instanceof Interface_) {
7373
$this->processInterface($node);
7474
}
7575

7676
if ($node instanceof Class_) {
7777
if ($node->isAnonymous()) {
78-
return;
78+
return null;
7979
}
8080

8181
$this->processClass($node);
@@ -86,20 +86,22 @@ public function enterNode(Node $node): void
8686
}
8787

8888
if (!$node instanceof Function_) {
89-
return;
89+
return null;
9090
}
9191

9292
$this->processFunction($node);
93+
94+
return null;
9395
}
9496

95-
public function leaveNode(Node $node): void
97+
public function leaveNode(Node $node): null
9698
{
9799
if (!$node instanceof Class_) {
98-
return;
100+
return null;
99101
}
100102

101103
if ($node->isAnonymous()) {
102-
return;
104+
return null;
103105
}
104106

105107
$traits = [];
@@ -111,7 +113,7 @@ public function leaveNode(Node $node): void
111113
}
112114

113115
if (empty($traits)) {
114-
return;
116+
return null;
115117
}
116118

117119
$namespacedClassName = $node->namespacedName->toString();
@@ -130,6 +132,8 @@ public function leaveNode(Node $node): void
130132
$traits,
131133
$this->classes[$namespacedClassName]->methods(),
132134
);
135+
136+
return null;
133137
}
134138

135139
/**

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(string $source)
5454
$this->source = $source;
5555
}
5656

57-
public function enterNode(Node $node): void
57+
public function enterNode(Node $node): null
5858
{
5959
foreach ($node->getComments() as $comment) {
6060
$commentLine = $comment->getStartLine();
@@ -80,15 +80,15 @@ public function enterNode(Node $node): void
8080
}
8181
}
8282

83-
return;
83+
return null;
8484
}
8585

8686
if ($node instanceof Node\Stmt\Interface_) {
8787
foreach (range($node->getStartLine(), $node->getEndLine()) as $line) {
8888
$this->unsets[$line] = true;
8989
}
9090

91-
return;
91+
return null;
9292
}
9393

9494
if ($node instanceof Node\Stmt\Declare_ ||
@@ -113,7 +113,7 @@ public function enterNode(Node $node): void
113113
$node instanceof Node\Name ||
114114
$node instanceof Node\Param ||
115115
$node instanceof Node\Scalar) {
116-
return;
116+
return null;
117117
}
118118

119119
if ($node instanceof Node\Expr\Match_) {
@@ -125,13 +125,13 @@ public function enterNode(Node $node): void
125125
);
126126
}
127127

128-
return;
128+
return null;
129129
}
130130

131131
if ($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Throw_) {
132132
$this->setLineBranch($node->expr->expr->getEndLine(), $node->expr->expr->getEndLine(), ++$this->nextBranch);
133133

134-
return;
134+
return null;
135135
}
136136

137137
if ($node instanceof Node\Stmt\Enum_ ||
@@ -176,7 +176,7 @@ public function enterNode(Node $node): void
176176
}
177177

178178
if ($isConcreteClassLike) {
179-
return;
179+
return null;
180180
}
181181

182182
$hasEmptyBody = [] === $node->stmts ||
@@ -188,15 +188,15 @@ public function enterNode(Node $node): void
188188

189189
if ($hasEmptyBody) {
190190
if ($node->getEndLine() === $node->getStartLine() && isset($this->executableLinesGroupedByBranch[$node->getStartLine()])) {
191-
return;
191+
return null;
192192
}
193193

194194
$this->setLineBranch($node->getEndLine(), $node->getEndLine(), ++$this->nextBranch);
195195

196-
return;
196+
return null;
197197
}
198198

199-
return;
199+
return null;
200200
}
201201

202202
if ($node instanceof Node\Expr\ArrowFunction) {
@@ -208,12 +208,12 @@ public function enterNode(Node $node): void
208208
$endLine = $node->expr->getEndLine();
209209

210210
if ($endLine < $startLine) {
211-
return;
211+
return null;
212212
}
213213

214214
$this->setLineBranch($startLine, $endLine, ++$this->nextBranch);
215215

216-
return;
216+
return null;
217217
}
218218

219219
if ($node instanceof Node\Expr\Ternary) {
@@ -226,22 +226,22 @@ public function enterNode(Node $node): void
226226
$this->setLineBranch($node->else->getStartLine(), $node->else->getEndLine(), ++$this->nextBranch);
227227
}
228228

229-
return;
229+
return null;
230230
}
231231

232232
if ($node instanceof Node\Expr\BinaryOp\Coalesce) {
233233
if ($node->getStartLine() !== $node->getEndLine()) {
234234
$this->setLineBranch($node->getEndLine(), $node->getEndLine(), ++$this->nextBranch);
235235
}
236236

237-
return;
237+
return null;
238238
}
239239

240240
if ($node instanceof Node\Stmt\If_ ||
241241
$node instanceof Node\Stmt\ElseIf_ ||
242242
$node instanceof Node\Stmt\Case_) {
243243
if (null === $node->cond) {
244-
return;
244+
return null;
245245
}
246246

247247
$this->setLineBranch(
@@ -250,7 +250,7 @@ public function enterNode(Node $node): void
250250
++$this->nextBranch,
251251
);
252252

253-
return;
253+
return null;
254254
}
255255

256256
if ($node instanceof Node\Stmt\For_) {
@@ -292,7 +292,7 @@ public function enterNode(Node $node): void
292292
}
293293

294294
if (null === $startLine || null === $endLine) {
295-
return;
295+
return null;
296296
}
297297

298298
$this->setLineBranch(
@@ -301,7 +301,7 @@ public function enterNode(Node $node): void
301301
++$this->nextBranch,
302302
);
303303

304-
return;
304+
return null;
305305
}
306306

307307
if ($node instanceof Node\Stmt\Foreach_) {
@@ -311,7 +311,7 @@ public function enterNode(Node $node): void
311311
++$this->nextBranch,
312312
);
313313

314-
return;
314+
return null;
315315
}
316316

317317
if ($node instanceof Node\Stmt\While_ ||
@@ -322,7 +322,7 @@ public function enterNode(Node $node): void
322322
++$this->nextBranch,
323323
);
324324

325-
return;
325+
return null;
326326
}
327327

328328
if ($node instanceof Node\Stmt\Catch_) {
@@ -337,7 +337,7 @@ public function enterNode(Node $node): void
337337
++$this->nextBranch,
338338
);
339339

340-
return;
340+
return null;
341341
}
342342

343343
if ($node instanceof Node\Expr\CallLike) {
@@ -349,17 +349,19 @@ public function enterNode(Node $node): void
349349

350350
$this->setLineBranch($node->getStartLine(), $node->getEndLine(), $branch);
351351

352-
return;
352+
return null;
353353
}
354354

355355
if (isset($this->executableLinesGroupedByBranch[$node->getStartLine()])) {
356-
return;
356+
return null;
357357
}
358358

359359
$this->setLineBranch($node->getStartLine(), $node->getEndLine(), ++$this->nextBranch);
360+
361+
return null;
360362
}
361363

362-
public function afterTraverse(array $nodes): void
364+
public function afterTraverse(array $nodes): null
363365
{
364366
$lines = explode("\n", $this->source);
365367

@@ -379,6 +381,8 @@ public function afterTraverse(array $nodes): void
379381
$this->executableLinesGroupedByBranch,
380382
$this->unsets,
381383
);
384+
385+
return null;
382386
}
383387

384388
/**

src/StaticAnalysis/IgnoredLinesFindingVisitor.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(bool $useAnnotationsForIgnoringCode, bool $ignoreDep
3939
$this->ignoreDeprecated = $ignoreDeprecated;
4040
}
4141

42-
public function enterNode(Node $node): void
42+
public function enterNode(Node $node): null
4343
{
4444
if (!$node instanceof Class_ &&
4545
!$node instanceof Trait_ &&
@@ -48,11 +48,11 @@ public function enterNode(Node $node): void
4848
!$node instanceof ClassMethod &&
4949
!$node instanceof Function_ &&
5050
!$node instanceof Attribute) {
51-
return;
51+
return null;
5252
}
5353

5454
if ($node instanceof Class_ && $node->isAnonymous()) {
55-
return;
55+
return null;
5656
}
5757

5858
if ($node instanceof Class_ ||
@@ -68,11 +68,11 @@ public function enterNode(Node $node): void
6868
}
6969

7070
if (!$this->useAnnotationsForIgnoringCode) {
71-
return;
71+
return null;
7272
}
7373

7474
if ($node instanceof Interface_) {
75-
return;
75+
return null;
7676
}
7777

7878
if ($node instanceof Attribute &&
@@ -84,10 +84,12 @@ public function enterNode(Node $node): void
8484
$this->ignoredLines[] = $line;
8585
}
8686

87-
return;
87+
return null;
8888
}
8989

9090
$this->processDocComment($node);
91+
92+
return null;
9193
}
9294

9395
/**

0 commit comments

Comments
 (0)