Skip to content

Commit a2f0e6e

Browse files
committed
Fix small PHPStan issues
1 parent 2369559 commit a2f0e6e

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,6 @@ parameters:
576576
count: 1
577577
path: src/Rules/Generics/TemplateTypeCheck.php
578578

579-
-
580-
message: """
581-
#^Call to deprecated method getValue\\(\\) of class PHPStan\\\\Reflection\\\\ClassConstantReflection\\:
582-
Use getValueExpr\\(\\)$#
583-
"""
584-
count: 1
585-
path: src/Rules/Keywords/RequireFileExistsRule.php
586-
587-
-
588-
message: "#^Instanceof between PhpParser\\\\Node\\\\Name and PhpParser\\\\Node\\\\Name will always evaluate to true\\.$#"
589-
count: 1
590-
path: src/Rules/Keywords/RequireFileExistsRule.php
591-
592579
-
593580
message: "#^Method PHPStan\\\\Rules\\\\Keywords\\\\RequireFileExistsRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\RuleError\\}\\.$#"
594581
count: 1

src/Rules/Keywords/RequireFileExistsRule.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use PhpParser\Node\Expr\Include_;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleError;
910
use PHPStan\Rules\RuleErrorBuilder;
11+
use PHPStan\ShouldNotHappenException;
1012
use function is_string;
1113
use function sprintf;
1214

@@ -26,7 +28,7 @@ public function processNode(Node $node, Scope $scope): array
2628
$filePath = $this->resolveFilePath($node, $scope);
2729
if (is_string($filePath) && !is_file($filePath)) {
2830
return [
29-
$this->getErrorMessage($node, $filePath)->build()
31+
$this->getErrorMessage($node, $filePath)
3032
];
3133
}
3234
}
@@ -42,19 +44,20 @@ private function shouldProcessNode(Node $node): bool
4244
);
4345
}
4446

45-
private function getErrorMessage(Include_ $node, string $filePath): RuleErrorBuilder
47+
private function getErrorMessage(Include_ $node, string $filePath): RuleError
4648
{
4749
$message = match ($node->type) {
4850
Include_::TYPE_REQUIRE => 'Path in require() "%s" is not a file or it does not exist.',
4951
Include_::TYPE_REQUIRE_ONCE => 'Path in require_once() "%s" is not a file or it does not exist.',
52+
default => throw new ShouldNotHappenException('Rule should have already validated the node type.')
5053
};
5154

5255
return RuleErrorBuilder::message(
5356
sprintf(
5457
$message,
5558
$filePath,
5659
),
57-
);
60+
)->build();
5861
}
5962

6063
private function resolveFilePath(Include_ $node, Scope $scope): ?string

0 commit comments

Comments
 (0)