# ModelRulesReader

> Reads the validation rules that a yii\base\Model::rules() return passes unchanged to yii\base\Model::createValidators(), as proven by literals or by PHPStan's native types.

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

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

Reads the validation rules that a [`Model::rules()`](/docs/api/yii/base/model/index.md#method-rules) return passes unchanged to [`Model::createValidators()`](/docs/api/yii/base/model/index.md#method-createValidators),
as proven by literals or by PHPStan's native types.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`entries()`](#method-entries) static | Returns the entries of a rule list as `[index, line, rule type]`, in list order, or `null` when the list isn't certain. | `ModelRulesReader` |
| [`owner()`](#method-owner) static | Returns the class whose `rules()` returns the statement when [`Model`](/docs/api/yii/base/model/index.md) consumes it unchanged, or `null`. | `ModelRulesReader` |
| [`ruleValues()`](#method-ruleValues) static | Returns the value type at each key of a rule that native types prove to be one constant array without optional keys, or `null` for any other rule, such as a [`Validator`](/docs/api/yii/validators/validator/index.md) instance or a union. | `ModelRulesReader` |

## Method details

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

```php
public static function entries(PhpParser\Node\Expr $list, int $line, PHPStan\Analyser\Scope $scope): list<array{int|string, int, PHPStan\Type\Type}>|null
```

Returns the entries of a rule list as `[index, line, rule type]`, in list order, or `null` when the list isn't
certain.

Literal items keep their lines, with PHP's key normalization, implicit keys (after a negative key, its successor)
and last-duplicate semantics; other lists, and literals with unpacking or non-constant keys, must be one constant
array and use the return line.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$list` | `PhpParser\Node\Expr` | Returned rule list. |
| `$line` | `int` | Line of the return statement. |
| `$scope` | `PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

`list<array{int|string, int, PHPStan\Type\Type}>|null`: Native type of each rule, or `null` when the list isn't proven.

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

```php
public static function owner(PhpParser\Node\Stmt\Return_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): PHPStan\Reflection\ClassReflection|null
```

Returns the class whose `rules()` returns the statement when [`Model`](/docs/api/yii/base/model/index.md) consumes it unchanged, or `null`.

Only 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) qualify; returns in traits and closures don't. Records the declaration dependency of the owner before
checking its `createValidators()` and `getValidators()`, so that a transition out of an override reanalyses it.

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

`PHPStan\Reflection\ClassReflection|null`

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

```php
public static function ruleValues(PHPStan\Type\Type $rule): array<int|string, PHPStan\Type\Type>|null
```

Returns the value type at each key of a rule that native types prove to be one constant array without optional
keys, or `null` for any other rule, such as a [`Validator`](/docs/api/yii/validators/validator/index.md) instance or a union.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rule` | `PHPStan\Type\Type` | Native type of the rule. |

**Returns**

`array<int|string, PHPStan\Type\Type>|null`