# CreateObjectConstructionContract

> Represents how an API constructs a configured object: the inherited constructor, the arguments the API supplies, the configuration parameter and what must hold before the configuration is applied.

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

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

Represents how an API constructs a configured object: the inherited constructor, the arguments the API supplies, the
configuration parameter and what must hold before the configuration is applied.

Closed contract with two instances, [`baseObject()`](/docs/extensions/phpstan/reference/rules/createobjectconstructioncontract/index.md#method-baseObject) and [`externalAction()`](/docs/extensions/phpstan/reference/rules/createobjectconstructioncontract/index.md#method-externalAction).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-configurationName"></span>`$configurationName` readonly constructor | `string` | Name of the configuration parameter. | `CreateObjectConstructionContract` |
| <span id="property-configurationPosition"></span>`$configurationPosition` readonly constructor | `int` | Position of the configuration parameter, the last one. | `CreateObjectConstructionContract` |
| <span id="property-constructorClass"></span>`$constructorClass` readonly constructor | `string` | Class that must declare the inherited constructor. | `CreateObjectConstructionContract` |
| <span id="property-fixedArgumentPositions"></span>`$fixedArgumentPositions` readonly constructor | `list<int>` | Positions of the arguments the API supplies, `0` up to the configuration. | `CreateObjectConstructionContract` |
| <span id="property-followsConstructorArguments"></span>`$followsConstructorArguments` readonly constructor | `bool` | Whether a `__construct()` option and definition params that address only the configuration parameter are followed; otherwise any of them leaves the configuration unresolved. | `CreateObjectConstructionContract` |
| <span id="property-propertiesWrittenBeforeConfiguration"></span>`$propertiesWrittenBeforeConfiguration` readonly constructor | `list<string>` | Properties the constructor assigns before the configuration, which must be plain public properties. | `CreateObjectConstructionContract` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`baseObject()`](#method-baseObject) static | Returns the contract of [`BaseObject::__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct), used by `Yii::createObject()`, `new` and widgets. | `CreateObjectConstructionContract` |
| [`externalAction()`](#method-externalAction) static | Returns the contract of [`Action::__construct()`](/docs/api/yii/base/action/index.md#method-__construct) for `Yii::createObject($definition, [$id, $this])` in [`Controller::createAction()`](/docs/api/yii/base/controller/index.md#method-createAction). | `CreateObjectConstructionContract` |
| [`isInheritedConstructor()`](#method-isInheritedConstructor) | Returns whether the class inherits the contract's constructor with one variant whose parameters are the supplied arguments followed by the configuration parameter; optionality isn't compared. | `CreateObjectConstructionContract` |

## Method details

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

```php
public static function baseObject(): self
```

Returns the contract of [`BaseObject::__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct), used by `Yii::createObject()`, `new` and widgets.

**Returns**

`self`

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

```php
public static function externalAction(): self
```

Returns the contract of [`Action::__construct()`](/docs/api/yii/base/action/index.md#method-__construct) for `Yii::createObject($definition, [$id, $this])` in
[`Controller::createAction()`](/docs/api/yii/base/controller/index.md#method-createAction).

**Returns**

`self`

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

```php
public function isInheritedConstructor(PHPStan\Reflection\ClassReflection $classReflection): bool
```

Returns whether the class inherits the contract's constructor with one variant whose parameters are the supplied
arguments followed by the configuration parameter; optionality isn't compared.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` |  |

**Returns**

`bool`