Skip to content

Commit

Permalink
Modernize MatchingTypeInSwitchCaseConditionRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 16, 2020
1 parent a5f7d9c commit 65cc4d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,6 @@ parameters:
count: 1
path: src/Rules/StrictCalls/StrictFunctionCallsRule.php

-
message: "#^Class PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#"
count: 1
path: src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php

-
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\\(\\)$#"
count: 1
path: src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php

-
message: "#^Class PHPStan\\\\Rules\\\\VariableVariables\\\\VariableMethodCallRule implements generic interface PHPStan\\\\Rules\\\\Rule but does not specify its types\\: TNodeType$#"
count: 1
Expand Down Expand Up @@ -537,16 +527,6 @@ parameters:
count: 1
path: tests/Rules/StrictCalls/StrictFunctionCallsRuleTest.php

-
message: "#^Class PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRuleTest extends generic class PHPStan\\\\Testing\\\\RuleTestCase but does not specify its types\\: TRule$#"
count: 1
path: tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php

-
message: "#^Method PHPStan\\\\Rules\\\\SwitchConditions\\\\MatchingTypeInSwitchCaseConditionRuleTest\\:\\:getRule\\(\\) return type with generic interface PHPStan\\\\Rules\\\\Rule does not specify its types\\: TNodeType$#"
count: 1
path: tests/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRuleTest.php

-
message: "#^Class PHPStan\\\\Rules\\\\VariableVariables\\\\VariableMethodCallRuleTest extends generic class PHPStan\\\\Testing\\\\RuleTestCase but does not specify its types\\: TRule$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace PHPStan\Rules\SwitchConditions;

use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\VerbosityLevel;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Switch_>
*/
class MatchingTypeInSwitchCaseConditionRule implements \PHPStan\Rules\Rule
{

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

/**
* @param \PhpParser\Node\Stmt\Switch_ $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[] errors
*/
public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array
{
$messages = [];
Expand All @@ -39,12 +38,12 @@ public function processNode(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scop
continue;
}

$messages[] = sprintf(
$messages[] = RuleErrorBuilder::message(sprintf(
'Switch condition type (%s) does not match case condition %s (%s).',
$conditionType->describe(VerbosityLevel::value()),
$this->printer->prettyPrintExpr($case->cond),
$caseType->describe(VerbosityLevel::typeOnly())
);
))->build();
}

return $messages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use PHPStan\Rules\Rule;

/**
* @extends \PHPStan\Testing\RuleTestCase<MatchingTypeInSwitchCaseConditionRule>
*/
class MatchingTypeInSwitchCaseConditionRuleTest extends \PHPStan\Testing\RuleTestCase
{

Expand Down

0 comments on commit 65cc4d8

Please sign in to comment.