Skip to content
PHP Ecosystem
Explore

CreateObjectInvalidOptionTypeRule

API reference › PHPStan › rules › CreateObjectInvalidOptionTypeRule

final classyii2\extensions\phpstan\rules\CreateObjectInvalidOptionTypeRule
ImplementsRule
Sourcesrc/rules/CreateObjectInvalidOptionTypeRule.php

Reports BaseYii::createObject() option values that the property or setter Yii assigns them to never accepts.

A value is reported 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. PHPDoc types are not consulted. 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. The class and __class keys with which BaseYii::createObject() selects the class are never checked; inside a constructor argument used as the configuration they are checked like any other option.

Rule for PHPStan rule contract. CreateObjectConfigurationResolver for the configurations and classes the rule analyses. ObjectOptionAssignment for the assignment semantics.

MethodDescriptionDefined by
__construct()Initializes the rule with class reflection and the analysis configuration.CreateObjectInvalidOptionTypeRule
getNodeType()Returns the node class this rule analyses.CreateObjectInvalidOptionTypeRule
processNode()Returns one error per distinct option whose value the created class never accepts.CreateObjectInvalidOptionTypeRule
public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap)

Initializes the rule 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 function getNodeType(): class-string<PhpParser\Node\Expr\StaticCall>

Returns the node class this rule analyses.

Returns

class-string<PhpParser\Node\Expr\StaticCall>

public function processNode(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<PHPStan\Rules\IdentifierRuleError>

Returns one error per distinct option whose value the created class never accepts.

Parameters

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

Returns

list<PHPStan\Rules\IdentifierRuleError>: Errors reported at the first key of each option, or at the call line when the configuration doesn’t locate the key.