CreateObjectConfigurationResolver
API reference › PHPStan › rules › CreateObjectConfigurationResolver
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.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Initializes the resolver with class reflection and the analysis configuration. | CreateObjectConfigurationResolver |
rejectedOptions() static | Returns 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 |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
RESERVED_OPTIONS | ['__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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap)Initializes the resolver with class reflection and the analysis configuration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$reflectionProvider | PHPStan\ | Provides class reflection for the created class. |
$serviceMap | yii2\ | Service and component map for Yii Application static analysis. |
rejectedOptions()
Section titled “rejectedOptions() ”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
| Parameter | Type | Description |
|---|---|---|
$configuration | CreateObjectConfiguration | Resolved configuration. |
$scope | PHPStan\ | Current 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.
resolve()
Section titled “resolve() ”public function resolve(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): yii2\extensions\phpstan\rules\CreateObjectConfiguration|nullReturns 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
| Parameter | Type | Description |
|---|---|---|
$node | PhpParser\ | Static call to inspect. |
$scope | PHPStan\ | Current 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.
resolveTypeOptions()
Section titled “resolveTypeOptions() ”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|nullReturns 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
| Parameter | Type | Description |
|---|---|---|
$calledClass | string | Class through which createObject() is called, as PHPStan displays it. |
$typeOptions | list<array{string, | Name, reported line and effective value of each option of the $type configuration, in the order Yii receives them. |
$line | int | Line of the call, for options the configuration doesn’t locate. |
$scope | PHPStan\ | Current PHPStan analysis scope. |
$contract | CreateObjectConstructionContract| | Construction 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.