88use PHPStan \TrinaryLogic ;
99use PHPStan \Type \Type ;
1010
11+ use function sprintf ;
12+
1113/**
1214 * Property reflection wrapper for Yii application components in PHPStan analysis.
1315 *
@@ -38,9 +40,14 @@ final class ComponentPropertyReflection implements PropertyReflection
3840 * Creates a new instance of the {@see ComponentPropertyReflection} class.
3941 *
4042 * @param PropertyReflection $fallbackProperty Fallback property reflection instance for delegation.
41- * @param Type $type Actual type of the dynamic component as resolved by the service map.
43+ * @param Type $type Type of the dynamic component as resolved by the service map or dependency injection.
44+ * @param ClassReflection $declaringClass Class reflection of the class declaring the dynamic property.
4245 */
43- public function __construct (private readonly PropertyReflection $ fallbackProperty , private readonly Type $ type ) {}
46+ public function __construct (
47+ private readonly PropertyReflection $ fallbackProperty ,
48+ private readonly Type $ type ,
49+ private readonly ClassReflection $ declaringClass ,
50+ ) {}
4451
4552 /**
4653 * Determines whether the type of the dynamic Yii application component property can change after assignment.
@@ -71,7 +78,7 @@ public function canChangeTypeAfterAssignment(): bool
7178 */
7279 public function getDeclaringClass (): ClassReflection
7380 {
74- return $ this ->fallbackProperty -> getDeclaringClass () ;
81+ return $ this ->declaringClass ;
7582 }
7683
7784 /**
@@ -99,11 +106,13 @@ public function getDeprecatedDescription(): string|null
99106 * This method allows static analysis tools and IDEs to display inline documentation for dynamic application
100107 * components, supporting accurate code completion, type checking, and developer guidance.
101108 *
102- * @return string|null PHPDoc comment string if available , or `null` if no documentation is set.
109+ * @return string PHPDoc comment string for the property , or an empty string if no comment is set.
103110 */
104- public function getDocComment (): string | null
111+ public function getDocComment (): string
105112 {
106- return $ this ->fallbackProperty ->getDocComment ();
113+ $ componentTypeName = $ this ->type ->describe (\PHPStan \Type \VerbosityLevel::typeOnly ());
114+
115+ return sprintf ("/** \n * @var %s \n */ " , $ componentTypeName );
107116 }
108117
109118 /**
@@ -119,7 +128,7 @@ public function getDocComment(): string|null
119128 */
120129 public function getReadableType (): Type
121130 {
122- return $ this ->fallbackProperty -> getReadableType () ;
131+ return $ this ->type ;
123132 }
124133
125134 /**
@@ -151,7 +160,7 @@ public function getType(): Type
151160 */
152161 public function getWritableType (): Type
153162 {
154- return $ this ->fallbackProperty -> getWritableType () ;
163+ return $ this ->type ;
155164 }
156165
157166 /**
@@ -167,7 +176,7 @@ public function getWritableType(): Type
167176 */
168177 public function isDeprecated (): TrinaryLogic
169178 {
170- return $ this -> fallbackProperty -> isDeprecated ();
179+ return TrinaryLogic:: createNo ();
171180 }
172181
173182 /**
@@ -183,7 +192,7 @@ public function isDeprecated(): TrinaryLogic
183192 */
184193 public function isInternal (): TrinaryLogic
185194 {
186- return $ this -> fallbackProperty -> isInternal ();
195+ return TrinaryLogic:: createNo ();
187196 }
188197
189198 /**
0 commit comments