diff --git a/CHANGELOG.md b/CHANGELOG.md index a4561b8..135e7a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # ChangeLog -## 0.2.1 Under development +## 0.2.2 Under development + +- Enh #10: Add generic PHPStan annotations to `Reflector` for typed attribute inference in consumers (@terabytesoftw) ## 0.2.1 March 3, 2026 diff --git a/src/Reflector.php b/src/Reflector.php index 5e437fe..e5903df 100644 --- a/src/Reflector.php +++ b/src/Reflector.php @@ -71,7 +71,9 @@ public static function cacheSize(): int * * @return array Class attributes. * - * @phpstan-return list> + * @phpstan-template TAttribute of object + * @phpstan-param class-string|null $attribute + * @phpstan-return ($attribute is null ? list> : list>) */ public static function classAttributes(object|string $class, string|null $attribute = null, int $flags = 0): array { @@ -111,6 +113,10 @@ public static function clearCache(): void * ``` * * @return object|null First matching instantiated attribute, or `null` if no matching attribute is found. + * + * @phpstan-template TAttribute of object + * @phpstan-param class-string $attribute + * @phpstan-return TAttribute|null */ public static function firstPropertyAttribute( object|string $class, @@ -205,7 +211,9 @@ public static function property(object|string $class, string $property): Reflect * * @return array Instantiated property attributes. * - * @phpstan-return list + * @phpstan-template TAttribute of object + * @phpstan-param class-string|null $attribute + * @phpstan-return ($attribute is null ? list : list) */ public static function propertyAttributeInstances( object|string $class, @@ -236,7 +244,9 @@ public static function propertyAttributeInstances( * * @return array Property attributes. * - * @phpstan-return list> + * @phpstan-template TAttribute of object + * @phpstan-param class-string|null $attribute + * @phpstan-return ($attribute is null ? list> : list>) */ public static function propertyAttributes( object|string $class,