Skip to content
PHP Ecosystem
Explore

ObjectConfigurationReader

API reference › PHPStan › rules › ObjectConfigurationReader

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

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.

MethodDescriptionDefined by
constantArray() staticReturns the only constant array a native type can hold, without optional keys or an unsealed part.ObjectConfigurationReader
constantString() staticReturns the value of a native type that holds exactly one constant string.ObjectConfigurationReader
keyLines() staticReturns the first line of each key of an array literal without unpacking, by option name.ObjectConfigurationReader
options() staticReturns 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() staticReturns 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
public static function constantArray(PHPStan\Type\Type $type): PHPStan\Type\Constant\ConstantArrayType|null

Returns 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

ParameterTypeDescription
$typePHPStan\Type\Type

Returns

PHPStan\Type\Constant\ConstantArrayType|null

public static function constantString(PHPStan\Type\Type $type): string|null

Returns the value of a native type that holds exactly one constant string.

Parameters

ParameterTypeDescription
$typePHPStan\Type\Type

Returns

string|null

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

ParameterTypeDescription
$configPhpParser\Node\Expr
$scopePHPStan\Analyser\Scope

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.

public static function options(PhpParser\Node\Expr $config, int $callLine, PHPStan\Analyser\Scope $scope): list<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}>|null

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.

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

ParameterTypeDescription
$configPhpParser\Node\ExprConfiguration expression.
$callLineintLine of the call, for options the configuration doesn’t locate.
$scopePHPStan\Analyser\Scope

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.

public static function optionsFromType(PHPStan\Type\Type $type, int $line): list<array{string, int, PHPStan\Type\Type}>|null

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.

Parameters

ParameterTypeDescription
$typePHPStan\Type\TypeNative type of the configuration, one constant array as constantArray() describes.
$lineintLine 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.