# ValidatorInvalidDefinitionRule

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

[API reference](/docs/api/index.md) › [PHPStan](/docs/extensions/phpstan/reference/index.md) › [rules](/docs/extensions/phpstan/reference/rules/index.md) › ValidatorInvalidDefinitionRule

| final class | `yii2\extensions\phpstan\rules\ValidatorInvalidDefinitionRule` |
| --- | --- |
| Implements | [`Rule`](https://apiref.phpstan.org/2.3.x/PHPStan.Rules.Rule.html) |
| Source | [`src/rules/ValidatorInvalidDefinitionRule.php`](https://github.com/yii2-extensions/phpstan/blob/main/src/rules/ValidatorInvalidDefinitionRule.php#L30) |

Reports validation rules returned by [`Model::rules()`](/docs/api/yii/base/model/index.md#method-rules) whose validator type at key `1` is an array or an object
other than a [`Closure`](https://www.php.net/manual/en/class.closure.php), which [`Validator::createValidator()`](/docs/api/yii/validators/validator/index.md#method-createValidator) looks up as a key of
`Validator::$builtInValidators` and so rejects with a [`TypeError`](https://www.php.net/manual/en/class.typeerror.php).

Only `rules()` returns of non-anonymous [`Model`](/docs/api/yii/base/model/index.md) subclasses that inherit `createValidators()` and
`getValidators()` from [`Model`](/docs/api/yii/base/model/index.md) 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`](https://www.php.net/manual/en/class.closure.php) or a valid key, unions with such types, incomplete rules and
[`Validator`](/docs/api/yii/validators/validator/index.md) instances stand aside.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`getNodeType()`](#method-getNodeType) | Returns the node class this rule analyses. | `ValidatorInvalidDefinitionRule` |
| [`processNode()`](#method-processNode) | Returns one error per returned rule whose validator type can't be a key of `Validator::$builtInValidators`. | `ValidatorInvalidDefinitionRule` |

## Method details

### getNodeType() <span id="method-getNodeType"></span>

```php
public function getNodeType(): class-string<PhpParser\Node\Stmt\Return_>
```

Returns the node class this rule analyses.

**Returns**

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

### processNode() <span id="method-processNode"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$node` | `PhpParser\Node\Stmt\Return_` | Return statement to inspect. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

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