Skip to content
PHP Ecosystem
Explore

CreateObjectConfigurationResolver

API reference › PHPStan › rules › CreateObjectConfigurationResolver

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

Resolves the class and options of a BaseYii::createObject() call whose assignment path Yii makes certain.

Requires keys and class proven by literals or native types, a container ID that is unbound or bound only through definitions that name a class (ServiceMap::getConfiguredClassById()) and whose options, if any, are all plain public properties of the created class, and a created class that inherits the constructor of the CreateObjectConstructionContract and the __set() of BaseObject or Component.

Constructor arguments from $params, a __construct() option and the definitions on the chain are accepted, when the contract follows them, if their keys, merged as Container::build() merges them, name at most the configuration parameter (0 or config for BaseObject). Yii then assigns the options of the configuration when there are any, and otherwise uses that argument as the configuration, which is resolved only when the call supplies it.

The resolved options are the ones Yii assigns, in order: the options of the $type configuration without the class and __class keys that select the class, or every key of the argument used as the configuration, class, __class and __construct() included, which BaseYii::configure() assigns as ordinary properties.

ServiceMap for service and component map for Yii Application static analysis.

MethodDescriptionDefined by
__construct()Initializes the resolver with class reflection and the analysis configuration.CreateObjectConfigurationResolver
rejectedOptions() staticReturns the options of a resolved configuration whose value the created class never accepts, in configuration order.CreateObjectConfigurationResolver
resolve()Returns the configuration that Yii assigns to the created class through BaseObject::__set() or Component::__set() semantics: the options of the call without its class keys, or every key of the constructor argument that the call supplies as configuration when neither the call nor a definition has options.CreateObjectConfigurationResolver
resolveTypeOptions()Returns the configuration that Yii assigns for a $type configuration array that an API passes to BaseYii::createObject() with no $params besides the contract’s fixed arguments, under the conditions of resolve().CreateObjectConfigurationResolver
ConstantValueDescriptionDefined by
RESERVED_OPTIONS['__class', 'class']Options that BaseYii::createObject() removes from its $type configuration to select the class, before configuring the object; a constructor argument used as the configuration keeps them.CreateObjectConfigurationResolver
public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap)

Initializes the resolver with class reflection and the analysis configuration.

Parameters

ParameterTypeDescription
$reflectionProviderPHPStan\Reflection\ReflectionProviderProvides class reflection for the created class.
$serviceMapyii2\extensions\phpstan\ServiceMapService and component map for Yii Application static analysis.
public static function rejectedOptions(yii2\extensions\phpstan\rules\CreateObjectConfiguration $configuration, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<array{string, int, PHPStan\Type\Type, PHPStan\Type\Type, string}>

Returns the options of a resolved configuration whose value the created class never accepts, in configuration order.

A value is returned only when PHP’s weak type coercion can’t convert it to the native type of the public property or of the first setter parameter. A value that may be an Instance reference is also checked as the object or null that the container may resolve it to before the assignment.

Parameters

ParameterTypeDescription
$configurationCreateObjectConfigurationResolved configuration.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.

Returns

list<array{string, int, PHPStan\Type\Type, PHPStan\Type\Type, string}>: Name, reported line, value type, expected native type and member description of each rejected option.

public function resolve(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): yii2\extensions\phpstan\rules\CreateObjectConfiguration|null

Returns the configuration that Yii assigns to the created class through BaseObject::__set() or Component::__set() semantics: the options of the call without its class keys, or every key of the constructor argument that the call supplies as configuration when neither the call nor a definition has options.

Records the construction dependency of the container ID before deciding, and the declaration dependency of the created class once known, so that the result cache reanalyses the call when a definition on the chain or that class changes.

Parameters

ParameterTypeDescription
$nodePhpParser\Node\Expr\StaticCallStatic call to inspect.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.

Returns

CreateObjectConfiguration|null: Resolved configuration, or null when the call, the configuration, the constructor arguments or the created class isn’t proven, or a definition supplies the configuration.

public function resolveTypeOptions(string $calledClass, list<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}> $typeOptions, int $line, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope, yii2\extensions\phpstan\rules\CreateObjectConstructionContract|null $contract = null): yii2\extensions\phpstan\rules\CreateObjectConfiguration|null

Returns the configuration that Yii assigns for a $type configuration array that an API passes to BaseYii::createObject() with no $params besides the contract’s fixed arguments, under the conditions of resolve().

Records the same construction and declaration dependencies as resolve().

Parameters

ParameterTypeDescription
$calledClassstringClass through which createObject() is called, as PHPStan displays it.
$typeOptionslist<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}>Name, reported line and effective value of each option of the $type configuration, in the order Yii receives them.
$lineintLine of the call, for options the configuration doesn’t locate.
$scopePHPStan\Analyser\DependencyTracker&PHPStan\Analyser\ScopeCurrent PHPStan analysis scope.
$contractCreateObjectConstructionContract|nullConstruction contract of the API, or null for CreateObjectConstructionContract::baseObject().

Returns

CreateObjectConfiguration|null: Resolved configuration, or null when the class value, the constructor arguments or the created class isn’t proven, or a definition supplies the configuration.