class AssertSameBooleanExpectedRule
@implements Rule<NodeAbstract>
Hierarchy
- class \PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule implements \PHPStan\Rules\Rule
Expanded class hierarchy of AssertSameBooleanExpectedRule
File
-
vendor/
phpstan/ phpstan-phpunit/ src/ Rules/ PHPUnit/ AssertSameBooleanExpectedRule.php, line 16
Namespace
PHPStan\Rules\PHPUnitView source
class AssertSameBooleanExpectedRule implements Rule {
public function getNodeType() : string {
return NodeAbstract::class;
}
public function processNode(Node $node, Scope $scope) : array {
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
return [];
}
if (count($node->getArgs()) < 2) {
return [];
}
if (!$node->name instanceof Node\Identifier || $node->name
->toLowerString() !== 'assertsame') {
return [];
}
$expectedArgumentValue = $node->getArgs()[0]->value;
if (!$expectedArgumentValue instanceof ConstFetch) {
return [];
}
if ($expectedArgumentValue->name
->toLowerString() === 'true') {
return [
RuleErrorBuilder::message('You should use assertTrue() instead of assertSame() when expecting "true"')->identifier('phpunit.assertTrue')
->build(),
];
}
if ($expectedArgumentValue->name
->toLowerString() === 'false') {
return [
RuleErrorBuilder::message('You should use assertFalse() instead of assertSame() when expecting "false"')->identifier('phpunit.assertFalse')
->build(),
];
}
return [];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
AssertSameBooleanExpectedRule::getNodeType | public | function | |
AssertSameBooleanExpectedRule::processNode | public | function |