# WidgetConfigurationResolver

> Resolves the widget class and options of a yii\base\Widget::widget() or yii\base\Widget::begin() call whose assignment path Yii makes certain.

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

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

Resolves the widget class and options of a [`Widget::widget()`](/docs/api/yii/base/widget/index.md#method-widget) or [`Widget::begin()`](/docs/api/yii/base/widget/index.md#method-begin) call whose assignment
path Yii makes certain.

Both methods set the `class` key of their configuration to the called class and pass it to
[`BaseYii::createObject()`](/docs/api/yii/baseyii/index.md#method-createObject) without `$params`, so the configuration is resolved as
[`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions) resolves that array: a non-`null` `__class` value
selects the class instead, and container definitions, `__construct()` and the configurable class are handled as for
`Yii::createObject()`.

Requires the called class written as a name (an imported alias or a fully qualified name, never `self`, `parent` or
`static`) that is [`Widget`](/docs/api/yii/base/widget/index.md) or a subclass, a method that [`Widget`](/docs/api/yii/base/widget/index.md) declares and the class doesn't override,
the configuration as the only argument by position or by its parameter name and proven as
[`ObjectConfigurationReader::options()`](/docs/extensions/phpstan/reference/rules/objectconfigurationreader/index.md#method-options) describes, and a created class that is a [`Widget`](/docs/api/yii/base/widget/index.md) subclass.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes the resolver with class reflection and the analysis configuration. | `WidgetConfigurationResolver` |
| [`resolve()`](#method-resolve) | Returns the configuration that Yii assigns to the widget that the call creates. | `WidgetConfigurationResolver` |

## 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 the called and created classes. |
| `$serviceMap` | [`yii2\extensions\phpstan\ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) | Service and component map for Yii Application static analysis. |

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

```php
public function resolve(PhpParser\Node\Expr\StaticCall $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): yii2\extensions\phpstan\rules\WidgetConfiguration|null
```

Returns the configuration that Yii assigns to the widget that the call creates.

Records the declaration dependency of the called class before deciding, so that the result cache reanalyses the
call when that class starts or stops overriding the method, and the construction and declaration dependencies of
[`CreateObjectConfigurationResolver::resolveTypeOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-resolveTypeOptions).

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

[`WidgetConfiguration`](/docs/extensions/phpstan/reference/rules/widgetconfiguration/index.md)`|null`: Resolved configuration, or `null` when the call, its configuration or the created widget isn't proven, or the call has no configuration.