# NewObjectInvalidOptionTypeRule

> Reports configuration values of a direct new construction 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) › NewObjectInvalidOptionTypeRule

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

Reports configuration values of a direct `new` construction that the property or setter Yii assigns them to never
accepts.

A value is reported only when PHP's weak type coercion, which applies inside [`BaseYii::configure()`](/docs/api/yii/baseyii/index.md#method-configure) and `__set()`
whatever the `strict_types` mode of the constructing file, can't convert it to the native type of the public
property or of the first setter parameter. PHPDoc types are not consulted. An [`Instance`](/docs/api/yii/di/instance/index.md) value is assigned as
that object, since `new` doesn't resolve container references.

[`Rule`](https://apiref.phpstan.org/2.3.x/PHPStan.Rules.Rule.html) for PHPStan rule contract.
[`NewObjectConfigurationResolver`](/docs/extensions/phpstan/reference/rules/newobjectconfigurationresolver/index.md) for the constructions 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. | `NewObjectInvalidOptionTypeRule` |
| [`getNodeType()`](#method-getNodeType) | Returns the node class this rule analyses. | `NewObjectInvalidOptionTypeRule` |
| [`processNode()`](#method-processNode) | Returns one error per distinct option whose value the constructed class never accepts. | `NewObjectInvalidOptionTypeRule` |

## Method details

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

```php
public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider)
```

Initializes the rule with class reflection.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$reflectionProvider` | `PHPStan\Reflection\ReflectionProvider` | Provides class reflection for the constructed class. |

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

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

Returns the node class this rule analyses.

**Returns**

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

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

```php
public function processNode(PhpParser\Node\Expr\New_ $node, PHPStan\Analyser\DependencyTracker&PHPStan\Analyser\Scope $scope): list<PHPStan\Rules\IdentifierRuleError>
```

Returns one error per distinct option whose value the constructed class never accepts.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$node` | `PhpParser\Node\Expr\New_` | Construction 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 line of `new` when the configuration doesn't locate the key.