ObjectOptionAssignment
API reference › PHPStan › rules › ObjectOptionAssignment
Decides how Yii assigns configuration options to a BaseObject or Component subclass through
BaseYii::configure() and __set(), independently of how the object is constructed.
Callers pass only the options that Yii assigns, in assignment order: a construction API that removes keys before the
assignment, such as the class and __class keys that BaseYii::createObject() consumes from its $type
configuration, removes them first, and keeps every key of a configuration that Yii assigns as is.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
isConfigurable() static | Returns whether the class is instantiable and inherits the constructor of the contract and the __set() of BaseObject or Component, so that its configuration is assigned by BaseYii::configure(). | ObjectOptionAssignment |
isRedeclaredByTrait() static | Returns whether a trait of the class or of a parent class up to the declaring class of the native property, or a trait of those traits, declares the property with other visibility, hook, static or readonly modifiers than the declaration PHPStan reports, as a PHP 8.5 trait that redeclares an inherited property may do. | ObjectOptionAssignment |
rejectingTarget() static | Returns the native type that rejects every value of the actual type and the member that declares it, or null when Yii assigns the option to no member with a type check or the member may accept a value of that type. | ObjectOptionAssignment |
unknownOptions() static | Returns the options that the class can’t assign, in configuration order. | ObjectOptionAssignment |
Method details
Section titled “Method details”isConfigurable()
Section titled “isConfigurable() ”public static function isConfigurable(PHPStan\Reflection\ClassReflection $classReflection, yii2\extensions\phpstan\rules\CreateObjectConstructionContract|null $contract = null): boolReturns whether the class is instantiable and inherits the constructor of the contract and the __set() of
BaseObject or Component, so that its configuration is assigned by BaseYii::configure().
Parameters
| Parameter | Type | Description |
|---|---|---|
$classReflection | PHPStan\ | |
$contract | CreateObjectConstructionContract| | Construction contract, null for CreateObjectConstructionContract::baseObject(). |
Returns
bool
isRedeclaredByTrait()
Section titled “isRedeclaredByTrait() ”public static function isRedeclaredByTrait(PHPStan\Reflection\ClassReflection $classReflection, string $name): boolReturns whether a trait of the class or of a parent class up to the declaring class of the native property, or a
trait of those traits, declares the property with other visibility, hook, static or readonly modifiers than
the declaration PHPStan reports, as a PHP 8.5 trait that redeclares an inherited property may do.
The declaring class shadows the traits of its ancestors except for their hooks, which a redeclaration without hooks inherits, so only the hooks of those traits are compared. The class must have the native property.
Parameters
| Parameter | Type | Description |
|---|---|---|
$classReflection | PHPStan\ | |
$name | string |
Returns
bool
rejectingTarget()
Section titled “rejectingTarget() ”public static function rejectingTarget(PHPStan\Reflection\ClassReflection $classReflection, string $name, PHPStan\Type\Type $actualType, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): array{PHPStan\Type\Type, string}|nullReturns the native type that rejects every value of the actual type and the member that declares it, or null
when Yii assigns the option to no member with a type check or the member may accept a value of that type.
Records the declaration dependency of every class named by both types.
Parameters
| Parameter | Type | Description |
|---|---|---|
$classReflection | PHPStan\ | |
$name | string | Option name, compared as Yii does. |
$actualType | PHPStan\ | Native type of the value Yii assigns. |
$scope | PHPStan\ | Current PHPStan analysis scope. |
Returns
array{PHPStan\Type\Type, string}|null: Native type and member description.
unknownOptions()
Section titled “unknownOptions() ”public static function unknownOptions(PHPStan\Reflection\ClassReflection $classReflection, list<array{string, int, mixed}> $options, yii2\extensions\phpstan\ServiceMap $serviceMap, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<array{string, int}>Returns the options that the class can’t assign, in configuration order.
For a Component subclass, on ... and as ... options are never returned, and other options only when no
behavior can receive them: behaviors() and ensureBehaviors() inherited from Component, no as ...
option, no entry of the analysis behaviors map for any ancestor, and no earlier option that runs a setter, a
set hook or an overridden on().
Parameters
| Parameter | Type | Description |
|---|---|---|
$classReflection | PHPStan\ | |
$options | list<array{string, | Name, reported line and value of each option Yii assigns. |
$serviceMap | yii2\ | Service and component map for Yii Application static analysis. |
$scope | PHPStan\ | Current PHPStan analysis scope. |
Returns
list<array{string, int}>: Name and reported line of each unknown option.