ObjectConfigurationReader
API reference › PHPStan › rules › ObjectConfigurationReader
Reads the options of a Yii object configuration whose keys are proven by literals or by PHPStan’s native types.
BaseYii::configure() for the assignment of each option.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
constantArray() static | Returns the only constant array a native type can hold, without optional keys or an unsealed part. | ObjectConfigurationReader |
constantString() static | Returns the value of a native type that holds exactly one constant string. | ObjectConfigurationReader |
keyLines() static | Returns the first line of each key of an array literal without unpacking, by option name. | ObjectConfigurationReader |
options() static | Returns the distinct options of a configuration, in first-occurrence order, each with the line it is reported at and its effective value, as PHP builds the array. | ObjectConfigurationReader |
optionsFromType() static | Returns the options of a configuration known only as a native type, all located at the given line, since a type keeps no source positions. | ObjectConfigurationReader |
Method details
Section titled “Method details”constantArray()
Section titled “constantArray() ”public static function constantArray(PHPStan\Type\Type $type): PHPStan\Type\Constant\ConstantArrayType|nullReturns the only constant array a native type can hold, without optional keys or an unsealed part.
A single constant array doesn’t prove the value on its own: an intersection can synthesize one for a callable array, so the array must also contain every value of the type.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | PHPStan\ |
Returns
PHPStan\Type\Constant\ConstantArrayType|null
constantString()
Section titled “constantString() ”public static function constantString(PHPStan\Type\Type $type): string|nullReturns the value of a native type that holds exactly one constant string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | PHPStan\ |
Returns
string|null
keyLines()
Section titled “keyLines() ”public static function keyLines(PhpParser\Node\Expr $config, PHPStan\Analyser\Scope $scope): array<int|string, int>Returns the first line of each key of an array literal without unpacking, by option name.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | PhpParser\ | |
$scope | PHPStan\ |
Returns
array<int|string, int>: Line by option name; empty when the expression isn’t such a literal or a key doesn’t have one constant string value, so that no option is located at an item it may not come from.
options()
Section titled “options() ”public static function options(PhpParser\Node\Expr $config, int $callLine, PHPStan\Analyser\Scope $scope): list<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}>|nullReturns the distinct options of a configuration, in first-occurrence order, each with the line it is reported at and its effective value, as PHP builds the array.
An array literal without unpacking whose keys are all literal strings yields the value expression of the last item of each key, located at its first item. Any other configuration must have a native type that is one constant array with string keys; it yields the value types, located at their first key when the configuration is an array literal without unpacking whose keys all have one constant string value, otherwise at the given line.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | PhpParser\ | Configuration expression. |
$callLine | int | Line of the call, for options the configuration doesn’t locate. |
$scope | PHPStan\ |
Returns
list<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}>|null: Name, line and effective value of each option, or null when neither form proves the configuration, including a native type with more than one array, an optional key or an integer key.
optionsFromType()
Section titled “optionsFromType() ”public static function optionsFromType(PHPStan\Type\Type $type, int $line): list<array{string, int, PHPStan\Type\Type}>|nullReturns the options of a configuration known only as a native type, all located at the given line, since a type keeps no source positions.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | PHPStan\ | Native type of the configuration, one constant array as constantArray() describes. |
$line | int | Line every option is reported at. |
Returns
list<array{string, int, PHPStan\Type\Type}>|null: Name, line and value type of each option, or null when the type isn’t one such array or has an integer key.