Skip to content
PHP Ecosystem
Explore

ModelRulesReader

API reference › PHPStan › rules › ModelRulesReader

final classyii2\extensions\phpstan\rules\ModelRulesReader
Sourcesrc/rules/ModelRulesReader.php

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

MethodDescriptionDefined by
entries() staticReturns the entries of a rule list as [index, line, rule type], in list order, or null when the list isn’t certain.ModelRulesReader
owner() staticReturns the class whose rules() returns the statement when Model consumes it unchanged, or null.ModelRulesReader
ruleValues() staticReturns 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
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

ParameterTypeDescription
$listPhpParser\Node\ExprReturned rule list.
$lineintLine of the return statement.
$scopePHPStan\Analyser\ScopeCurrent 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.

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

ParameterTypeDescription
$nodePhpParser\Node\Stmt\Return_Return statement to inspect.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.

Returns

PHPStan\Reflection\ClassReflection|null

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 instance or a union.

Parameters

ParameterTypeDescription
$rulePHPStan\Type\TypeNative type of the rule.

Returns

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