# WidgetInvalidOptionTypeRule

> Reports yii\base\Widget::widget() and yii\base\Widget::begin() option values that the property or setter Yii assigns them to never accepts.

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

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

Reports [`Widget::widget()`](/docs/api/yii/base/widget/index.md#method-widget) and [`Widget::begin()`](/docs/api/yii/base/widget/index.md#method-begin) 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`](/docs/api/yii/di/instance/index.md) 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 `Yii::createObject()` selects the class are never checked; inside a constructor argument
used as the configuration they are checked like any other option.

[`Rule`](https://apiref.phpstan.org/2.3.x/PHPStan.Rules.Rule.html) for PHPStan rule contract.
[`WidgetConfigurationResolver`](/docs/extensions/phpstan/reference/rules/widgetconfigurationresolver/index.md) for the calls and classes the rule analyses.
[`CreateObjectConfigurationResolver::rejectedOptions()`](/docs/extensions/phpstan/reference/rules/createobjectconfigurationresolver/index.md#method-rejectedOptions) for the type semantics.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes the rule with class reflection and the analysis configuration. | `WidgetInvalidOptionTypeRule` |
| [`getNodeType()`](#method-getNodeType) | Returns the node class this rule analyses. | `WidgetInvalidOptionTypeRule` |
| [`processNode()`](#method-processNode) | Returns one error per distinct option whose value the created widget never accepts. | `WidgetInvalidOptionTypeRule` |

## 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 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. |

### 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 whose value the created widget never accepts.

**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 option, or at the call line when the configuration doesn't locate the key.