# ObjectConfigurationReader

> Reads the options of a Yii object configuration whose keys are proven by literals or by PHPStan's native types.

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

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

Reads the options of a Yii object configuration whose keys are proven by literals or by PHPStan's native types.

[`BaseYii::configure()`](/docs/api/yii/baseyii/index.md#method-configure) for the assignment of each option.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`constantArray()`](#method-constantArray) static | Returns the only constant array a native type can hold, without optional keys or an unsealed part. | `ObjectConfigurationReader` |
| [`constantString()`](#method-constantString) static | Returns the value of a native type that holds exactly one constant string. | `ObjectConfigurationReader` |
| [`keyLines()`](#method-keyLines) static | Returns the first line of each key of an array literal without unpacking, by option name. | `ObjectConfigurationReader` |
| [`options()`](#method-options) static | Returns the distinct options of a configuration, in first-occurrence order, each with the line it is reported at and its effective value, as PHP builds the array. | `ObjectConfigurationReader` |
| [`optionsFromType()`](#method-optionsFromType) static | Returns the options of a configuration known only as a native type, all located at the given line, since a type keeps no source positions. | `ObjectConfigurationReader` |

## Method details

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

```php
public static function constantArray(PHPStan\Type\Type $type): PHPStan\Type\Constant\ConstantArrayType|null
```

Returns the only constant array a native type can hold, without optional keys or an unsealed part.

A single constant array doesn't prove the value on its own: an intersection can synthesize one for a callable
array, so the array must also contain every value of the type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `PHPStan\Type\Type` |  |

**Returns**

`PHPStan\Type\Constant\ConstantArrayType|null`

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

```php
public static function constantString(PHPStan\Type\Type $type): string|null
```

Returns the value of a native type that holds exactly one constant string.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `PHPStan\Type\Type` |  |

**Returns**

`string|null`

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

```php
public static function keyLines(PhpParser\Node\Expr $config, PHPStan\Analyser\Scope $scope): array<int|string, int>
```

Returns the first line of each key of an array literal without unpacking, by option name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `PhpParser\Node\Expr` |  |
| `$scope` | `PHPStan\Analyser\Scope` |  |

**Returns**

`array<int|string, int>`: Line by option name; empty when the expression isn't such a literal or a key doesn't have one constant string value, so that no option is located at an item it may not come from.

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

```php
public static function options(PhpParser\Node\Expr $config, int $callLine, PHPStan\Analyser\Scope $scope): list<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}>|null
```

Returns the distinct options of a configuration, in first-occurrence order, each with the line it is reported at
and its effective value, as PHP builds the array.

An array literal without unpacking whose keys are all literal strings yields the value expression of the last
item of each key, located at its first item. Any other configuration must have a native type that is one constant
array with string keys; it yields the value types, located at their first key when the configuration is an array
literal without unpacking whose keys all have one constant string value, otherwise at the given line.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `PhpParser\Node\Expr` | Configuration expression. |
| `$callLine` | `int` | Line of the call, for options the configuration doesn't locate. |
| `$scope` | `PHPStan\Analyser\Scope` |  |

**Returns**

`list<array{string, int, PhpParser\Node\Expr|PHPStan\Type\Type}>|null`: Name, line and effective value of each option, or `null` when neither form proves the configuration, including a native type with more than one array, an optional key or an integer key.

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

```php
public static function optionsFromType(PHPStan\Type\Type $type, int $line): list<array{string, int, PHPStan\Type\Type}>|null
```

Returns the options of a configuration known only as a native type, all located at the given line, since a type
keeps no source positions.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `PHPStan\Type\Type` | Native type of the configuration, one constant array as [`constantArray()`](/docs/extensions/phpstan/reference/rules/objectconfigurationreader/index.md#method-constantArray) describes. |
| `$line` | `int` | Line every option is reported at. |

**Returns**

`list<array{string, int, PHPStan\Type\Type}>|null`: Name, line and value type of each option, or `null` when the type isn't one such array or has an integer key.