# ValidatorInvalidOptionTypeRule

> Reports option values written in model validation rules that the property or setter of the validator Yii creates never accepts.

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

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

Reports option values written in model validation rules that the property or setter of the validator Yii creates
never accepts.

A value is reported only when PHP's weak type coercion can't convert its native type to the native type of the public
property or of the first setter parameter; PHPDoc types are not consulted. Only options that the rule writes and Yii
assigns unchanged are reported: alias defaults, `attributes` and the `method` of a closure rule, which
`Validator::createValidator()` replaces with the closure, are not.

[`ValidatorConfigurationResolver`](/docs/extensions/phpstan/reference/rules/validatorconfigurationresolver/index.md) for the dispatch, including the declared alias table assumption.
[`CreateObjectConfigurationResolver::rejectedOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-rejectedOptions) for the checks.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes static class reflection and the analysis service map. | `ValidatorInvalidOptionTypeRule` |
| [`getNodeType()`](#method-getNodeType) | Returns the node class this rule analyses. | `ValidatorInvalidOptionTypeRule` |
| [`processNode()`](#method-processNode) | Returns one diagnostic per written option whose value the created validator never accepts. | `ValidatorInvalidOptionTypeRule` |

## Method details

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

```php
public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap)
```

Initializes static class reflection and the analysis service map.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$reflectionProvider` | `PHPStan\Reflection\ReflectionProvider` |  |
| `$serviceMap` | [`yii2\extensions\phpstan\ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) |  |

### 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 diagnostic per written option whose value the created validator never accepts.

**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 at each rule's line.