# CreateObjectUnknownOptionRule

> Reports yii\BaseYii::createObject() options that Yii can't assign to the created object.

[API reference](/docs/api/index.md) › [PHPStan](/docs/extensions/phpstan/reference/index.md) › [rules](/docs/extensions/phpstan/reference/rules/index.md) › CreateObjectUnknownOptionRule

| final class | `yii2\extensions\phpstan\rules\CreateObjectUnknownOptionRule` |
| --- | --- |
| Implements | [`Rule`](https://apiref.phpstan.org/2.3.x/PHPStan.Rules.Rule.html) |
| Source | [`src/rules/CreateObjectUnknownOptionRule.php`](https://github.com/yii2-extensions/phpstan/blob/main/src/rules/CreateObjectUnknownOptionRule.php#L30) |

Reports [`BaseYii::createObject()`](/docs/api/yii/baseyii/index.md#method-createObject) options that Yii can't assign to the created object.

For a [`Component`](/docs/api/yii/base/component/index.md) subclass, `on ...` and `as ...` options are never reported, and other options only when no
behavior can receive them. The `class` and `__class` keys with which [`BaseYii::createObject()`](/docs/api/yii/baseyii/index.md#method-createObject) selects the class
are never reported; inside a constructor argument used as the configuration they are options like any other.

[`Rule`](https://apiref.phpstan.org/2.3.x/PHPStan.Rules.Rule.html) for PHPStan rule contract.
[`CreateObjectConfigurationResolver`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md) for the configurations and classes the rule analyses.
[`ObjectOptionAssignment`](/docs/extensions/phpstan/reference/rules/objectoptionassignment/index.md) for the assignment semantics.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes the rule with class reflection and the analysis configuration. | `CreateObjectUnknownOptionRule` |
| [`getNodeType()`](#method-getNodeType) | Returns the node class this rule analyses. | `CreateObjectUnknownOptionRule` |
| [`processNode()`](#method-processNode) | Returns one error per distinct option that the created class can't assign. | `CreateObjectUnknownOptionRule` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap)
```

Initializes the rule with class reflection and the analysis configuration.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$reflectionProvider` | `PHPStan\Reflection\ReflectionProvider` | Provides class reflection for the created class. |
| `$serviceMap` | [`yii2\extensions\phpstan\ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) | Service and component map for Yii Application static analysis. |

### getNodeType() <span id="method-getNodeType"></span>

```php
public function getNodeType(): class-string<PhpParser\Node\Expr\StaticCall>
```

Returns the node class this rule analyses.

**Returns**

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

### processNode() <span id="method-processNode"></span>

```php
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 that the created class can't assign.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$node` | `PhpParser\Node\Expr\StaticCall` | Static call to inspect. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

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