# BehaviorDefinitionResolver

> Finds behavior definitions that yii\base\Component can't attach, and behavior configuration options that the created yii\base\Behavior can't assign or whose value it never accepts, in behaviors() returns, attachBehavior() and attachBehaviors() arguments and as options of Yii::createObject() configurations.

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

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

Finds behavior definitions that [`Component`](/docs/api/yii/base/component/index.md) can't attach, and behavior configuration options that the created
[`Behavior`](/docs/api/yii/base/behavior/index.md) can't assign or whose value it never accepts, in `behaviors()` returns, `attachBehavior()` and
`attachBehaviors()` arguments and `as` options of `Yii::createObject()` configurations.

A definition or option is reported only when Yii certainly fails on it; dynamic, uncertain or overridden paths stand
aside. Options are classified by [`ObjectOptionAssignment::unknownOptions()`](/docs/extensions/phpstan/reference/rules/objectoptionassignment/index.md#method-unknownOptions) and
[`CreateObjectConfigurationResolver::rejectedOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-rejectedOptions).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes the resolver with class reflection and the analysis configuration. | `BehaviorDefinitionResolver` |
| [`resolveAttachCall()`](#method-resolveAttachCall) | Returns the definitions of an `attachBehavior()` or `attachBehaviors()` call that can't be attached. | `BehaviorDefinitionResolver` |
| [`resolveAttachCallInvalidOptionTypes()`](#method-resolveAttachCallInvalidOptionTypes) | Returns the options of the behavior configurations of an `attachBehavior()` or `attachBehaviors()` call whose value the created behavior never accepts, in definition and configuration order. | `BehaviorDefinitionResolver` |
| [`resolveAttachCallUnknownOptions()`](#method-resolveAttachCallUnknownOptions) | Returns the options of the behavior configurations of an `attachBehavior()` or `attachBehaviors()` call that the created behavior can't assign, in definition and configuration order. | `BehaviorDefinitionResolver` |
| [`resolveBehaviorsReturn()`](#method-resolveBehaviorsReturn) | Returns the definitions of a `behaviors()` return statement that can't be attached. | `BehaviorDefinitionResolver` |
| [`resolveBehaviorsReturnInvalidOptionTypes()`](#method-resolveBehaviorsReturnInvalidOptionTypes) | Returns the options of the behavior configurations of a `behaviors()` return statement whose value the created behavior never accepts, in definition and configuration order. | `BehaviorDefinitionResolver` |
| [`resolveBehaviorsReturnUnknownOptions()`](#method-resolveBehaviorsReturnUnknownOptions) | Returns the options of the behavior configurations of a `behaviors()` return statement that the created behavior can't assign, in definition and configuration order. | `BehaviorDefinitionResolver` |
| [`resolveCreateObjectAsInvalidOptionTypes()`](#method-resolveCreateObjectAsInvalidOptionTypes) | Returns the options of the behavior configurations in the `as` options of a `Yii::createObject()` call whose value the created behavior never accepts, in configuration order. | `BehaviorDefinitionResolver` |
| [`resolveCreateObjectAsOptions()`](#method-resolveCreateObjectAsOptions) | Returns the `as` options of a `Yii::createObject()` call that the created component rejects or can't attach, in configuration order. | `BehaviorDefinitionResolver` |
| [`resolveCreateObjectAsUnknownOptions()`](#method-resolveCreateObjectAsUnknownOptions) | Returns the options of the behavior configurations in the `as` options of a `Yii::createObject()` call that the created behavior can't assign, in configuration order. | `BehaviorDefinitionResolver` |

## Method details

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

```php
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\Reflection\ReflectionProvider` | Provides class reflection for owners and resolved classes. |
| `$serviceMap` | [`yii2\extensions\phpstan\ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) | Service and component map for Yii Application static analysis. |

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

```php
public function resolveAttachCall(PhpParser\Node\Expr\MethodCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\InvalidBehaviorDefinition>
```

Returns the definitions of an `attachBehavior()` or `attachBehaviors()` call that can't be attached.

Records the `construction:<id>` value dependency and the class dependency of each resolved definition.

**Parameters**

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

**Returns**

`list<`[`InvalidBehaviorDefinition`](/docs/extensions/phpstan/reference/rules/invalidbehaviordefinition/index.md)`>`

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

```php
public function resolveAttachCallInvalidOptionTypes(PhpParser\Node\Expr\MethodCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\InvalidBehaviorOptionType>
```

Returns the options of the behavior configurations of an `attachBehavior()` or `attachBehaviors()` call whose
value the created behavior never accepts, in definition and configuration order.

Records the dependencies of [`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions) and
[`ObjectOptionAssignment::rejectingTarget()`](/docs/extensions/phpstan/reference/rules/objectoptionassignment/index.md#method-rejectingTarget) for each configuration.

**Parameters**

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

**Returns**

`list<`[`InvalidBehaviorOptionType`](/docs/extensions/phpstan/reference/rules/invalidbehavioroptiontype/index.md)`>`

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

```php
public function resolveAttachCallUnknownOptions(PhpParser\Node\Expr\MethodCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\UnknownBehaviorOption>
```

Returns the options of the behavior configurations of an `attachBehavior()` or `attachBehaviors()` call that the
created behavior can't assign, in definition and configuration order.

Records the dependencies of [`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions) for each
configuration.

**Parameters**

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

**Returns**

`list<`[`UnknownBehaviorOption`](/docs/extensions/phpstan/reference/rules/unknownbehavioroption/index.md)`>`

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

```php
public function resolveBehaviorsReturn(PhpParser\Node\Stmt\Return_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\InvalidBehaviorDefinition>
```

Returns the definitions of a `behaviors()` return statement that can't be attached.

Records the declaration dependency of the owner, and the `construction:<id>` value dependency and the class
dependency of each resolved definition.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$node` | `PhpParser\Node\Stmt\Return_` | Return statement to inspect. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

`list<`[`InvalidBehaviorDefinition`](/docs/extensions/phpstan/reference/rules/invalidbehaviordefinition/index.md)`>`

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

```php
public function resolveBehaviorsReturnInvalidOptionTypes(PhpParser\Node\Stmt\Return_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\InvalidBehaviorOptionType>
```

Returns the options of the behavior configurations of a `behaviors()` return statement whose value the created
behavior never accepts, in definition and configuration order.

Records the declaration dependency of the owner and the dependencies of
[`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions) and
[`ObjectOptionAssignment::rejectingTarget()`](/docs/extensions/phpstan/reference/rules/objectoptionassignment/index.md#method-rejectingTarget) for each configuration.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$node` | `PhpParser\Node\Stmt\Return_` | Return statement to inspect. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

`list<`[`InvalidBehaviorOptionType`](/docs/extensions/phpstan/reference/rules/invalidbehavioroptiontype/index.md)`>`

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

```php
public function resolveBehaviorsReturnUnknownOptions(PhpParser\Node\Stmt\Return_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\UnknownBehaviorOption>
```

Returns the options of the behavior configurations of a `behaviors()` return statement that the created behavior
can't assign, in definition and configuration order.

Records the declaration dependency of the owner and the dependencies of
[`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions) for each configuration.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$node` | `PhpParser\Node\Stmt\Return_` | Return statement to inspect. |
| `$scope` | `PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope` | Current PHPStan analysis scope. |

**Returns**

`list<`[`UnknownBehaviorOption`](/docs/extensions/phpstan/reference/rules/unknownbehavioroption/index.md)`>`

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

```php
public function resolveCreateObjectAsInvalidOptionTypes(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\InvalidBehaviorOptionType>
```

Returns the options of the behavior configurations in the `as` options of a `Yii::createObject()` call whose
value the created behavior never accepts, in configuration order.

Reads the same configurations as [`resolveCreateObjectAsUnknownOptions()`](/docs/extensions/phpstan/reference/rules/behaviordefinitionresolver/index.md#method-resolveCreateObjectAsUnknownOptions), and records the same
dependencies and those of [`ObjectOptionAssignment::rejectingTarget()`](/docs/extensions/phpstan/reference/rules/objectoptionassignment/index.md#method-rejectingTarget).

**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<`[`InvalidBehaviorOptionType`](/docs/extensions/phpstan/reference/rules/invalidbehavioroptiontype/index.md)`>`

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

```php
public function resolveCreateObjectAsOptions(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\InvalidBehaviorAsDefinition>
```

Returns the `as` options of a `Yii::createObject()` call that the created component rejects or can't attach, in
configuration order.

Records the dependencies of [`CreateObjectConfigurationResolver::resolve()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolve), the class dependency of each
named class and, for an accepted class, the `construction:<id>` value dependency and the class dependency of its
container result.

**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<`[`InvalidBehaviorAsDefinition`](/docs/extensions/phpstan/reference/rules/invalidbehaviorasdefinition/index.md)`>`

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

```php
public function resolveCreateObjectAsUnknownOptions(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<yii2\extensions\phpstan\rules\UnknownBehaviorOption>
```

Returns the options of the behavior configurations in the `as` options of a `Yii::createObject()` call that the
created behavior can't assign, in configuration order.

Only configurations whose class `Component::__set()` certainly accepts are read, since it checks the supplied
class before `Yii::createObject()` assigns any option.

Records the dependencies of [`CreateObjectConfigurationResolver::resolve()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolve), the class dependency of each
accepted class and the dependencies of [`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions) for each
configuration.

**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<`[`UnknownBehaviorOption`](/docs/extensions/phpstan/reference/rules/unknownbehavioroption/index.md)`>`