ModelRulesReader
API reference › PHPStan › rules › ModelRulesReader
Reads the validation rules that a Model::rules() return passes unchanged to Model::createValidators(),
as proven by literals or by PHPStan’s native types.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
entries() static | Returns the entries of a rule list as [index,, in list order, or null when the list isn’t certain. | ModelRulesReader |
owner() static | Returns the class whose rules() returns the statement when Model consumes it unchanged, or null. | ModelRulesReader |
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 instance or a union. | ModelRulesReader |
Method details
Section titled “Method details”entries()
Section titled “entries() ”public static function entries(PhpParser\Node\Expr $list, int $line, PHPStan\Analyser\Scope $scope): list<array{int|string, int, PHPStan\Type\Type}>|nullReturns 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\ | Returned rule list. |
$line | int | Line of the return statement. |
$scope | PHPStan\ | 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()
Section titled “owner() ”public static function owner(PhpParser\Node\Stmt\Return_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): PHPStan\Reflection\ClassReflection|nullReturns the class whose rules() returns the statement when Model consumes it unchanged, or null.
Only non-anonymous Model subclasses that inherit createValidators() and getValidators() from
Model 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\ | Return statement to inspect. |
$scope | PHPStan\ | Current PHPStan analysis scope. |
Returns
PHPStan\Reflection\ClassReflection|null
ruleValues()
Section titled “ruleValues() ”public static function ruleValues(PHPStan\Type\Type $rule): array<int|string, PHPStan\Type\Type>|nullReturns 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 instance or a union.
Parameters
| Parameter | Type | Description |
|---|---|---|
$rule | PHPStan\ | Native type of the rule. |
Returns
array<int|string, PHPStan\Type\Type>|null