Skip to content

Commit 65cc4d8

Browse files
committed
Modernize MatchingTypeInSwitchCaseConditionRule
1 parent a5f7d9c commit 65cc4d8

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,6 @@ parameters:
232232
count: 1
233233
path: src/Rules/StrictCalls/StrictFunctionCallsRule.php
234234

235-
-
236-
message: "#^Class PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#"
237-
count: 1
238-
path: src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php
239-
240-
-
241-
message: "#^Parameter \\#1 \\$node \\(PhpParser\\\\Node\\\\Stmt\\\\Switch_\\) of method PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRule\\:\\:processNode\\(\\) should be contravariant with parameter \\$node \\(PhpParser\\\\Node\\) of method PHPStan\\\\Rules\\\\Rule\\<PhpParser\\\\Node\\>\\:\\:processNode\\(\\)$#"
242-
count: 1
243-
path: src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php
244-
245235
-
246236
message: "#^Class PHPStan\\\\Rules\\\\VariableVariables\\\\VariableMethodCallRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#"
247237
count: 1
@@ -537,16 +527,6 @@ parameters:
537527
count: 1
538528
path: tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php
539529

540-
-
541-
message: "#^Class PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRuleTest extends generic class PHPStan\\\\Testing\\\\RuleTestCase but does not specify its types\\: TRule$#"
542-
count: 1
543-
path: tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php
544-
545-
-
546-
message: "#^Method PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRuleTest\\:\\:getRule\\(\\) return type with generic interface PHPStan\\\\Rules\\\\Rule does not specify its types\\: TNodeType$#"
547-
count: 1
548-
path: tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php
549-
550530
-
551531
message: "#^Class PHPStan\\\\Rules\\\\VariableVariables\\\\VariableMethodCallRuleTest extends generic class PHPStan\\\\Testing\\\\RuleTestCase but does not specify its types\\: TRule$#"
552532
count: 1

src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
namespace PHPStan\Rules\SwitchConditions;
44

5+
use PHPStan\Rules\RuleErrorBuilder;
56
use PHPStan\Type\VerbosityLevel;
67

8+
/**
9+
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Switch_>
10+
*/
711
class MatchingTypeInSwitchCaseConditionRule implements \PHPStan\Rules\Rule
812
{
913

@@ -20,11 +24,6 @@ public function getNodeType(): string
2024
return \PhpParser\Node\Stmt\Switch_::class;
2125
}
2226

23-
/**
24-
* @param \PhpParser\Node\Stmt\Switch_ $node
25-
* @param \PHPStan\Analyser\Scope $scope
26-
* @return string[] errors
27-
*/
2827
public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array
2928
{
3029
$messages = [];
@@ -39,12 +38,12 @@ public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scop
3938
continue;
4039
}
4140

42-
$messages[] = sprintf(
41+
$messages[] = RuleErrorBuilder::message(sprintf(
4342
'Switch condition type (%s) does not match case condition %s (%s).',
4443
$conditionType->describe(VerbosityLevel::value()),
4544
$this->printer->prettyPrintExpr($case->cond),
4645
$caseType->describe(VerbosityLevel::typeOnly())
47-
);
46+
))->build();
4847
}
4948

5049
return $messages;

tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PHPStan\Rules\Rule;
66

7+
/**
8+
* @extends \PHPStan\Testing\RuleTestCase<MatchingTypeInSwitchCaseConditionRule>
9+
*/
710
class MatchingTypeInSwitchCaseConditionRuleTest extends \PHPStan\Testing\RuleTestCase
811
{
912

0 commit comments

Comments
 (0)