# NewObjectConfigurationResolver

> Resolves the class and configuration of a direct new construction 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) › NewObjectConfigurationResolver

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

Resolves the class and configuration of a direct `new` construction whose assignment path Yii makes certain.

Requires a class name written in the expression (an imported alias, `self` or `parent`, or `static` in a final
class, never inside a closure or an arrow function), a class that inherits the constructor of [`BaseObject`](/docs/api/yii/base/baseobject/index.md) and
the `__set()` of [`BaseObject`](/docs/api/yii/base/baseobject/index.md) or [`Component`](/docs/api/yii/base/component/index.md), and a configuration passed to that constructor's parameter by
position or by name and proven as [`ObjectConfigurationReader::options()`](/docs/extensions/phpstan/reference/rules/objectconfigurationreader/index.md#method-options) describes.

`new` doesn't consult `Yii::$container`, so container definitions never change the constructed class, and
[`BaseYii::configure()`](/docs/api/yii/baseyii/index.md#method-configure) assigns every key of the configuration.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Initializes the resolver with class reflection. | `NewObjectConfigurationResolver` |
| [`resolve()`](#method-resolve) | Returns the configuration that the inherited `BaseObject` constructor assigns to the constructed class. | `NewObjectConfigurationResolver` |

## Method details

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

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

Initializes the resolver with class reflection.

**Parameters**

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

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

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

Returns the configuration that the inherited `BaseObject` constructor assigns to the constructed class.

Records the declaration dependency of the constructed class once known, so that the result cache reanalyses the
construction when that class, a parent class or a trait changes.

**Parameters**

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

**Returns**

[`NewObjectConfiguration`](/docs/extensions/phpstan/reference/rules/newobjectconfiguration/index.md)`|null`: Resolved configuration, or `null` when the class, its constructor and `__set()`, the arguments or the configuration isn't proven.