# ApplicationPropertiesClassReflectionExtension

> Resolves dynamic component properties on the Yii Application instance for PHPStan analysis.

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

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

Resolves dynamic component properties on the Yii Application instance for PHPStan analysis.

Recognizes properties defined via configuration, dependency injection, or service mapping on base, web, and console
application contexts, even when not declared natively. Delegates to annotation-based and native property reflection,
and resolves component types (including generics) through the [`ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md).

[`Application`](/docs/api/yii/base/application/index.md) for Yii Base Application class.
[`Application`](/docs/api/yii/console/application/index.md) for Yii Console Application class.
[`Application`](/docs/api/yii/web/application/index.md) for Yii Web Application class.
[`PropertiesClassReflectionExtension`](https://apiref.phpstan.org/2.3.x/PHPStan.Reflection.PropertiesClassReflectionExtension.html) for custom properties class reflection extension contract.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a new instance of the [`ApplicationPropertiesClassReflectionExtension`](/docs/extensions/phpstan/reference/property/applicationpropertiesclassreflectionextension/index.md) class. | `ApplicationPropertiesClassReflectionExtension` |
| [`getProperty()`](#method-getProperty) | Retrieves the property reflection for a given property on the Yii Application class or its components. | `ApplicationPropertiesClassReflectionExtension` |
| [`hasProperty()`](#method-hasProperty) | Determines whether the specified property exists on the Yii Application class or its components. | `ApplicationPropertiesClassReflectionExtension` |

## Method details

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

```php
public function __construct(PHPStan\Reflection\Annotations\AnnotationsPropertiesClassReflectionExtension $annotationsProperties, PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap, PHPStan\Analyser\DeclarationDependencyTracker $dependencyTracker, string[] $genericComponents = [])
```

Creates a new instance of the [`ApplicationPropertiesClassReflectionExtension`](/docs/extensions/phpstan/reference/property/applicationpropertiesclassreflectionextension/index.md) class.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$annotationsProperties` | [`AnnotationsPropertiesClassReflectionExtension`](https://github.com/phpstan/phpstan-src/blob/2.3.0/src/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtension.php) | Extension for handling annotation-based properties. |
| `$reflectionProvider` | `PHPStan\Reflection\ReflectionProvider` | Reflection provider for class and property lookups. |
| `$serviceMap` | [`yii2\extensions\phpstan\ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) | Service and component map for Yii Application static analysis. |
| `$dependencyTracker` | `PHPStan\Analyser\DeclarationDependencyTracker` | Records the configuration values each class declaration depends on. |
| `$genericComponents` | `string[]` | Optional mapping of component property names to their generic type parameter keys in the component definition. |

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

```php
public function getProperty(PHPStan\Reflection\ClassReflection $classReflection, string $propertyName): PHPStan\Reflection\PropertyReflection
```

Retrieves the property reflection for a given property on the Yii Application class or its components.

Resolves, in order, a native property of the configured application type, a configured component, an
annotation-based property, and a configured component whose class can't be determined, typed as `object`. Such a
component takes precedence over the annotation, since its definition decides the value, unless it's an array
without a class key, which Yii completes from the core component the annotation describes. PHPStan calls this
method only after [`hasProperty()`](/docs/extensions/phpstan/reference/property/applicationpropertiesclassreflectionextension/index.md#method-hasProperty) returned `true` for the same class and property name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` | Reflection of the class being analyzed. |
| `$propertyName` | `string` | Name of the property to resolve. |

**Returns**

[`PropertyReflection`](https://apiref.phpstan.org/2.3.x/PHPStan.Reflection.PropertyReflection.html): Property reflection instance for the specified property.

**Throws**

- `PHPStan\ShouldNotHappenException`: if the property is neither native, a configured component, nor annotation-based.

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

```php
public function hasProperty(PHPStan\Reflection\ClassReflection $classReflection, string $propertyName): bool
```

Determines whether the specified property exists on the Yii Application class or its components.

Applies only to [`Application`](/docs/api/yii/base/application/index.md) and its subclasses, and checks native properties, dynamic components
registered via the service map, annotation-based properties, and components configured with an unknown class,
in the same order as [`getProperty()`](/docs/extensions/phpstan/reference/property/applicationpropertiesclassreflectionextension/index.md#method-getProperty).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$classReflection` | `PHPStan\Reflection\ClassReflection` | Reflection of the class being analyzed. |
| `$propertyName` | `string` | Name of the property to resolve. |

**Returns**

`bool`: `true` if the property exists as a native, component, or annotated property; `false` otherwise.