# ValidatorConfigurationResolver

> Resolves the validator class and options that yii\validators\Validator::createValidator() passes to Yii::createObject() for a Model::rules() entry using a closure, a qualified class name or one of Yii's declared built-in aliases.

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

| final readonly class | `yii2\extensions\phpstan\rules\ValidatorConfigurationResolver` |
| --- | --- |
| Source | [`src/rules/ValidatorConfigurationResolver.php`](https://github.com/yii2-extensions/phpstan/blob/main/src/rules/ValidatorConfigurationResolver.php#L33) |

Resolves the validator class and options that [`Validator::createValidator()`](/docs/api/yii/validators/validator/index.md#method-createValidator) passes to `Yii::createObject()`
for a `Model::rules()` entry using a closure, a qualified class name or one of Yii's declared built-in aliases.

Assumes the declared alias table has not been changed at runtime. Method names, other unqualified names, qualified
names under an overridden `hasMethod()` and incomplete or uncertain rules stand aside. Container definitions and the
created class follow [`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes static class reflection and the analysis service map. | `ValidatorConfigurationResolver` |
| [`resolve()`](#method-resolve) | Returns the configuration of the validator that Yii creates for the rule, or `null` when it isn't proven. | `ValidatorConfigurationResolver` |

## 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) |  |

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

```php
public function resolve(PHPStan\Reflection\ClassReflection $owner, PHPStan\Type\Type $rule, int $line, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): yii2\extensions\phpstan\rules\ValidatorConfiguration|null
```

Returns the configuration of the validator that Yii creates for the rule, or `null` when it isn't proven.

Records the declaration and source file dependencies of [`Validator`](/docs/api/yii/validators/validator/index.md) before reading its declared alias table,
and the dependencies of [`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$owner` | `PHPStan\Reflection\ClassReflection` | Model whose `rules()` returns the rule. |
| `$rule` | `PHPStan\Type\Type` | Native type of the rule. |
| `$line` | `int` | Line reported for the rule's options. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

[`ValidatorConfiguration`](/docs/extensions/phpstan/reference/rules/validatorconfiguration/index.md)`|null`