# BehaviorPropertiesClassReflectionExtension

> Resolves properties provided by behaviors attached to yii\base\Component subclasses for PHPStan analysis.

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

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

Resolves properties provided by behaviors attached to [`Component`](/docs/api/yii/base/component/index.md) subclasses for PHPStan analysis.

Inspects the behaviors attached to a given class via the [`ServiceMap`](/docs/extensions/phpstan/reference/servicemap/index.md) and determines whether any provide the
requested property, allowing PHPStan to recognize behavior properties as if they were natively declared.

[`Component`](/docs/api/yii/base/component/index.md) for Yii Component 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 [`BehaviorPropertiesClassReflectionExtension`](/docs/extensions/phpstan/reference/property/behaviorpropertiesclassreflectionextension/index.md) class. | `BehaviorPropertiesClassReflectionExtension` |
| [`getProperty()`](#method-getProperty) | Retrieves the reflection of a property provided by a behavior attached to the given class. | `BehaviorPropertiesClassReflectionExtension` |
| [`hasProperty()`](#method-hasProperty) | Determines whether the specified property exists on the given class, including properties provided by attached behaviors. | `BehaviorPropertiesClassReflectionExtension` |

## Method details

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

```php
public function __construct(PHPStan\Reflection\ReflectionProvider $reflectionProvider, yii2\extensions\phpstan\ServiceMap $serviceMap, PHPStan\Analyser\DeclarationDependencyTracker $dependencyTracker)
```

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$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. |

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

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

Retrieves the reflection of a property provided by a behavior attached to the given class.

PHPStan calls this method only after [`hasProperty()`](/docs/extensions/phpstan/reference/property/behaviorpropertiesclassreflectionextension/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): Reflection instance for the resolved property.

**Throws**

- `PHPStan\ShouldNotHappenException`: if no attached behavior provides the property.

### 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 given class, including properties provided by attached
behaviors.

Checks if the class is a subclass of [`Component`](/docs/api/yii/base/component/index.md) and doesn't already declare the property natively. If so,
inspect all behaviors attached to the class to determine if any provide the requested property.

This enables PHPStan to recognize available properties from behaviors as if they were natively declared on the
component class, supporting accurate static analysis and autocompletion.

**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 on the class via an attached behavior; `false` otherwise.