Skip to content
PHP Ecosystem
Explore

ValidatorInvalidDefinitionRule

API reference › PHPStan › rules › ValidatorInvalidDefinitionRule

final classyii2\extensions\phpstan\rules\ValidatorInvalidDefinitionRule
ImplementsRule
Sourcesrc/rules/ValidatorInvalidDefinitionRule.php

Reports validation rules returned by Model::rules() whose validator type at key 1 is an array or an object other than a Closure, which Validator::createValidator() looks up as a key of Validator::$builtInValidators and so rejects with a TypeError.

Only rules() returns of non-anonymous Model subclasses that inherit createValidators() and getValidators() from Model are analysed. Each rule must be one constant array that native types prove, with a non-null key 0; types that may be a Closure or a valid key, unions with such types, incomplete rules and Validator instances stand aside.

MethodDescriptionDefined by
getNodeType()Returns the node class this rule analyses.ValidatorInvalidDefinitionRule
processNode()Returns one error per returned rule whose validator type can’t be a key of Validator::$builtInValidators.ValidatorInvalidDefinitionRule
public function getNodeType(): class-string<PhpParser\Node\Stmt\Return_>

Returns the node class this rule analyses.

Returns

class-string<PhpParser\Node\Stmt\Return_>

public function processNode(PhpParser\Node\Stmt\Return_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<PHPStan\Rules\IdentifierRuleError>

Returns one error per returned rule whose validator type can’t be a key of Validator::$builtInValidators.

Records the declaration dependency of the owner, also when its overrides make the rule stand aside.

Parameters

ParameterTypeDescription
$nodePhpParser\Node\Stmt\Return_Return statement to inspect.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.

Returns

list<PHPStan\Rules\IdentifierRuleError>: Errors reported at the list item, else at the return line.