Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AssertSameNullExpectedRule.php

class AssertSameNullExpectedRule

@implements Rule<NodeAbstract>

Hierarchy

  • class \PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule implements \PHPStan\Rules\Rule

Expanded class hierarchy of AssertSameNullExpectedRule

File

vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/AssertSameNullExpectedRule.php, line 16

Namespace

PHPStan\Rules\PHPUnit
View source
class AssertSameNullExpectedRule 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() === 'null') {
            return [
                RuleErrorBuilder::message('You should use assertNull() instead of assertSame(null, $actual).')->identifier('phpunit.assertNull')
                    ->build(),
            ];
        }
        return [];
    }

}

Members

Title Sort descending Modifiers Object type Summary
AssertSameNullExpectedRule::getNodeType public function
AssertSameNullExpectedRule::processNode public function
RSS feed
Powered by Drupal