22
33declare (strict_types=1 );
44
5- namespace yii2 \extensions \phpstan \reflection ;
5+ namespace yii2 \extensions \phpstan \property ;
66
77use PHPStan \Reflection \{
88 ClassReflection ,
1313};
1414use PHPStan \Reflection \Annotations \AnnotationsPropertiesClassReflectionExtension ;
1515use PHPStan \Reflection \Dummy \DummyPropertyReflection ;
16- use PHPStan \Type \Constant \ConstantBooleanType ;
17- use PHPStan \Type \{IntegerType , NullType , ObjectType , StringType , TypeCombinator };
16+ use PHPStan \Type \{BooleanType , IntegerType , NullType , ObjectType , StringType , TypeCombinator };
1817use yii \web \User ;
18+ use yii2 \extensions \phpstan \reflection \ComponentPropertyReflection ;
1919use yii2 \extensions \phpstan \ServiceMap ;
2020
21+ use function in_array ;
22+ use function is_string ;
23+
2124/**
22- * Provides property reflection for a Yii user component in PHPStan analysis.
25+ * Provides property reflection for a Yii User component in PHPStan analysis.
2326 *
24- * Integrates Yii's {@see User::identity] property and annotation-based property reflection into the user component
25- * context, enabling accurate type inference and autocompletion for properties that are available on the user class.
27+ * Integrates a Yii User component {@see User::identity} property and annotation-based property reflection into the user
28+ * component context, enabling accurate type inference and autocompletion for properties that are available on the user
29+ * class.
2630 *
2731 * This extension allows PHPStan to recognize and reflect the {@see User::identity} property on the Yii user instance,
2832 * as well as properties defined natively or via annotations, even if they aren't declared as native properties on the
2933 * user class.
3034 *
3135 * The implementation delegates property lookups to annotation-based property extensions and native property reflection,
32- * while providing a custom reflection for the dynamic {@see User::identity] property.
36+ * while providing a custom reflection for the dynamic {@see User::identity} property.
3337 *
3438 * Key features.
3539 * - Ensures compatibility with PHPStan strict analysis and autocompletion.
36- * - Integrates annotation-based and native property reflection for the user component.
37- * - Provides accurate type inference for the dynamic {@see User::identity] property.
38- * - Supports dynamic and annotated property resolution for the user component.
40+ * - Integrates annotation-based and native property reflection for the {@see User} component.
41+ * - Provides accurate type inference for the dynamic {@see User::identity} property.
42+ * - Supports dynamic and annotated property resolution for the {@see User} component.
3943 *
40- * @see AnnotationsPropertiesClassReflectionExtension for annotation support.
41- * @see ComponentPropertyReflection for dynamic property reflection.
44+ * @see ComponentPropertyReflection for dynamic property reflection class.
4245 * @see PropertiesClassReflectionExtension for custom properties class reflection extension contract.
4346 *
4447 * @copyright Copyright (C) 2023 Terabytesoftw.
@@ -61,15 +64,16 @@ public function __construct(
6164 ) {}
6265
6366 /**
64- * Retrieves the property reflection for a given property on the Yii user component.
67+ * Retrieves the property reflection for a given property on the Yii User component.
6568 *
6669 * Resolves the property reflection for the specified property name by checking for the dynamic
67- * {@see User::identity} property, native properties, and annotation-based properties on the Yii user instance.
70+ * {@see User::identity} property, native properties, and annotation-based properties on the Yii User instance.
6871 *
69- * For the 'identity' property, it resolves the type based on the configured identityClass in the user component.
72+ * For the {@see User::identity} property, it resolves the type based on the configured {@see User::identityClass}
73+ * in the {@see User} component.
7074 *
71- * @param ClassReflection $classReflection Class reflection instance for the Yii user component .
72- * @param string $propertyName Name of the property to retrieve .
75+ * @param ClassReflection $classReflection Reflection of the class being analyzed .
76+ * @param string $propertyName Name of the property to resolve .
7377 *
7478 * @throws MissingPropertyFromReflectionException if the property doesn't exist or can't be resolved.
7579 *
@@ -99,7 +103,7 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
99103 if ($ propertyName === 'isGuest ' ) {
100104 return new ComponentPropertyReflection (
101105 new DummyPropertyReflection ($ propertyName ),
102- new ConstantBooleanType ( true ),
106+ new BooleanType ( ),
103107 $ classReflection ,
104108 );
105109 }
@@ -121,15 +125,16 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
121125 }
122126
123127 /**
124- * Determines whether the specified property exists on the Yii user component.
128+ * Determines whether the specified property exists on the Yii User component.
125129 *
126- * Checks for the existence of a property on the user instance by considering native properties,
127- * annotation-based properties, and the special ' identity' property.
130+ * Checks for the existence of a property on the user instance by considering native properties, annotation-based
131+ * properties, and the special {@see User:: identity} property.
128132 *
129- * @param ClassReflection $classReflection Class reflection instance for the Yii user component .
130- * @param string $propertyName Name of the property to check for existence .
133+ * @param ClassReflection $classReflection Reflection of the class being analyzed .
134+ * @param string $propertyName Name of the property to resolve .
131135 *
132- * @return bool `true` if the property exists as a native, annotated, or identity property; `false` otherwise.
136+ * @return bool `true` if the property exists as a native, annotated, or {@see User::identity} property; `false`
137+ * otherwise.
133138 */
134139 public function hasProperty (ClassReflection $ classReflection , string $ propertyName ): bool
135140 {
@@ -146,12 +151,12 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
146151 }
147152
148153 /**
149- * Attempts to resolve the identity class from the user component configuration.
154+ * Attempts to resolve the {@see User::identityClass} from the user component configuration.
150155 *
151- * This method tries to determine the identityClass configured for the user component
152- * by looking at the service map's user component configuration.
156+ * This method tries to determine the {@see User:: identityClass} configured for the user component by looking at the
157+ * service map's user component configuration.
153158 *
154- * @return string|null The fully qualified identity class name, or null if not found.
159+ * @return string|null Fully qualified {@see User::identityClass} name, or ` null` if not found.
155160 */
156161 private function getIdentityClass (): string |null
157162 {
0 commit comments