# ObjectOptionAssignment

> Decides how Yii assigns configuration options to a yii\base\BaseObject or yii\base\Component subclass through yii\BaseYii::configure() and __set(), independently of how the object is constructed.

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

| final class | `yii2\extensions\phpstan\rules\ObjectOptionAssignment` |
| --- | --- |
| Source | [`src/rules/ObjectOptionAssignment.php`](https://github.com/yii2-extensions/phpstan/blob/main/src/rules/ObjectOptionAssignment.php#L27) |

Decides how Yii assigns configuration options to a [`BaseObject`](/docs/api/yii/base/baseobject/index.md) or [`Component`](/docs/api/yii/base/component/index.md) subclass through
[`BaseYii::configure()`](/docs/api/yii/baseyii/index.md#method-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()`](/docs/api/yii/baseyii/index.md#method-createObject) consumes from its `$type`
configuration, removes them first, and keeps every key of a configuration that Yii assigns as is.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`isConfigurable()`](#method-isConfigurable) static | Returns whether the class is instantiable and inherits the constructor of the contract and the `__set()` of [`BaseObject`](/docs/api/yii/base/baseobject/index.md) or [`Component`](/docs/api/yii/base/component/index.md), so that its configuration is assigned by [`BaseYii::configure()`](/docs/api/yii/baseyii/index.md#method-configure). | `ObjectOptionAssignment` |
| [`isRedeclaredByTrait()`](#method-isRedeclaredByTrait) static | 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. | `ObjectOptionAssignment` |
| [`rejectingTarget()`](#method-rejectingTarget) static | 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. | `ObjectOptionAssignment` |
| [`unknownOptions()`](#method-unknownOptions) static | Returns the options that the class can't assign, in configuration order. | `ObjectOptionAssignment` |

## Method details

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

```php
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`](/docs/api/yii/base/baseobject/index.md) or [`Component`](/docs/api/yii/base/component/index.md), so that its configuration is assigned by [`BaseYii::configure()`](/docs/api/yii/baseyii/index.md#method-configure).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` |  |
| `$contract` | [`CreateObjectConstructionContract`](/docs/extensions/phpstan/reference/rules/createobjectconstructioncontract/index.md)`\|null` | Construction contract, `null` for [`CreateObjectConstructionContract::baseObject()`](/docs/extensions/phpstan/reference/rules/createobjectconstructioncontract/index.md#method-baseObject). |

**Returns**

`bool`

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

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` |  |
| `$name` | `string` |  |

**Returns**

`bool`

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

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` |  |
| `$name` | `string` | Option name, compared as Yii does. |
| `$actualType` | `PHPStan\Type\Type` | Native type of the value Yii assigns. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

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

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

```php
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`](/docs/api/yii/base/component/index.md) subclass, `on ...` and `as ...` options are never returned, and other options only when no
behavior can receive them: `behaviors()` and `ensureBehaviors()` inherited from [`Component`](/docs/api/yii/base/component/index.md), 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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` |  |
| `$options` | `list<array{string, int, mixed}>` | Name, reported line and value of each option Yii assigns. |
| `$serviceMap` | [`yii2\extensions\phpstan\ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) | Service and component map for Yii Application static analysis. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

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