Skip to content
PHP Ecosystem
Explore

ObjectOptionAssignment

API reference › PHPStan › rules › ObjectOptionAssignment

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

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.

MethodDescriptionDefined by
isConfigurable() staticReturns 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() staticReturns 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() staticReturns 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() staticReturns the options that the class can’t assign, in configuration order.ObjectOptionAssignment
public static function isConfigurable(PHPStan\Reflection\ClassReflection $classReflection, yii2\extensions\phpstan\rules\CreateObjectConstructionContract|null $contract = null): bool

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().

Parameters

ParameterTypeDescription
$classReflectionPHPStan\Reflection\ClassReflection
$contractCreateObjectConstructionContract|nullConstruction contract, null for CreateObjectConstructionContract::baseObject().

Returns

bool

public static function isRedeclaredByTrait(PHPStan\Reflection\ClassReflection $classReflection, string $name): bool

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.

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

ParameterTypeDescription
$classReflectionPHPStan\Reflection\ClassReflection
$namestring

Returns

bool

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

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.

Records the declaration dependency of every class named by both types.

Parameters

ParameterTypeDescription
$classReflectionPHPStan\Reflection\ClassReflection
$namestringOption name, compared as Yii does.
$actualTypePHPStan\Type\TypeNative type of the value Yii assigns.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.

Returns

array{PHPStan\Type\Type, string}|null: Native type and member description.

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

ParameterTypeDescription
$classReflectionPHPStan\Reflection\ClassReflection
$optionslist<array{string, int, mixed}>Name, reported line and value of each option Yii assigns.
$serviceMapyii2\extensions\phpstan\ServiceMapService and component map for Yii Application static analysis.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.

Returns

list<array{string, int}>: Name and reported line of each unknown option.