From 113b050c61dfd6d26125dad5484d0defce4693fd Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Sun, 26 Oct 2025 15:48:00 +0100 Subject: [PATCH] Improve Reflection API type hinting --- Reflection/Reflection.php | 2 +- Reflection/ReflectionAttribute.php | 11 ++-- Reflection/ReflectionClass.php | 66 +++++++++++------------ Reflection/ReflectionClassConstant.php | 17 +++--- Reflection/ReflectionConstant.php | 7 +++ Reflection/ReflectionEnum.php | 9 +++- Reflection/ReflectionEnumBackedCase.php | 4 ++ Reflection/ReflectionEnumUnitCase.php | 4 ++ Reflection/ReflectionFunction.php | 6 +-- Reflection/ReflectionFunctionAbstract.php | 12 ++--- Reflection/ReflectionIntersectionType.php | 2 +- Reflection/ReflectionMethod.php | 9 ++-- Reflection/ReflectionNamedType.php | 2 +- Reflection/ReflectionObject.php | 4 +- Reflection/ReflectionParameter.php | 20 +++---- Reflection/ReflectionProperty.php | 17 +++--- tests/Model/StubsContainer.php | 2 +- 17 files changed, 111 insertions(+), 83 deletions(-) diff --git a/Reflection/Reflection.php b/Reflection/Reflection.php index 34ad1e8ba..955dcd92e 100644 --- a/Reflection/Reflection.php +++ b/Reflection/Reflection.php @@ -16,7 +16,7 @@ class Reflection * * @link https://php.net/manual/en/reflection.getmodifiernames.php * @param int $modifiers Bitfield of the modifiers to get. - * @return string[] An array of modifier names. + * @return list An array of modifier names. */ #[TentativeType] public static function getModifierNames(#[LanguageLevelTypeAware(['8.0' => 'int'], default: '')] $modifiers): array {} diff --git a/Reflection/ReflectionAttribute.php b/Reflection/ReflectionAttribute.php index 4b0a57c0f..75528cc99 100644 --- a/Reflection/ReflectionAttribute.php +++ b/Reflection/ReflectionAttribute.php @@ -5,10 +5,13 @@ /** * @since 8.0 * - * @template T of object + * @template TAttributeClass of Attribute */ class ReflectionAttribute implements Reflector { + /** + * @var class-string + */ public string $name; /** @@ -30,7 +33,7 @@ private function __construct() {} /** * Gets attribute name * - * @return string The name of the attribute parameter. + * @return class-string The name of the attribute parameter. * @since 8.0 */ #[Pure] @@ -57,7 +60,7 @@ public function isRepeated(): bool {} /** * Gets list of passed attribute's arguments. * - * @return array + * @return list * @since 8.0 */ #[Pure] @@ -66,7 +69,7 @@ public function getArguments(): array {} /** * Creates a new instance of the attribute with passed arguments * - * @return T + * @return TAttributeClass * @since 8.0 */ public function newInstance(): object {} diff --git a/Reflection/ReflectionClass.php b/Reflection/ReflectionClass.php index 43c6ef2d8..e5e918d33 100644 --- a/Reflection/ReflectionClass.php +++ b/Reflection/ReflectionClass.php @@ -8,15 +8,15 @@ use JetBrains\PhpStorm\Pure; /** - * @template T of object * The ReflectionClass class reports information about a class. * * @link https://php.net/manual/en/class.reflectionclass.php + * @template TReflectedClass of object */ class ReflectionClass implements Reflector { /** - * @var class-string Name of the class, same as calling the {@see ReflectionClass::getName()} method + * @var class-string Name of the class, same as calling the {@see ReflectionClass::getName()} method */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] @@ -62,7 +62,7 @@ class ReflectionClass implements Reflector * Constructs a ReflectionClass * * @link https://php.net/manual/en/reflectionclass.construct.php - * @param class-string|T $objectOrClass Either a string containing the name of + * @param class-string|TReflectedClass $objectOrClass Either a string containing the name of * the class to reflect, or an object. * @throws ReflectionException if the class does not exist. */ @@ -95,7 +95,7 @@ public function __toString(): string {} * Gets class name * * @link https://php.net/manual/en/reflectionclass.getname.php - * @return string The class name. + * @return class-string The class name. */ #[Pure] #[TentativeType] @@ -189,7 +189,7 @@ public function getDocComment(): string|false {} * Gets the constructor of the class * * @link https://php.net/manual/en/reflectionclass.getconstructor.php - * @return ReflectionMethod|null A {@see ReflectionMethod} object reflecting + * @return ReflectionMethod|null A {@see ReflectionMethod} object reflecting * the class' constructor, or {@see null} if the class has no constructor. */ #[Pure] @@ -210,8 +210,8 @@ public function hasMethod(#[LanguageLevelTypeAware(['8.0' => 'string'], default: * Gets a ReflectionMethod for a class method. * * @link https://php.net/manual/en/reflectionclass.getmethod.php - * @param string $name The method name to reflect. - * @return ReflectionMethod A {@see ReflectionMethod} + * @param non-empty-string $name The method name to reflect. + * @return ReflectionMethod A {@see ReflectionMethod} * @throws ReflectionException if the method does not exist. */ #[Pure] @@ -224,7 +224,7 @@ public function getMethod(#[LanguageLevelTypeAware(['8.0' => 'string'], default: * @link https://php.net/manual/en/reflectionclass.getmethods.php * @param int|null $filter Filter the results to include only methods * with certain attributes. Defaults to no filtering. - * @return ReflectionMethod[] An array of {@see ReflectionMethod} objects + * @return list> An array of {@see ReflectionMethod} objects * reflecting each method. */ #[Pure] @@ -245,8 +245,8 @@ public function hasProperty(#[LanguageLevelTypeAware(['8.0' => 'string'], defaul * Gets a ReflectionProperty for a class's property * * @link https://php.net/manual/en/reflectionclass.getproperty.php - * @param string $name The property name. - * @return ReflectionProperty A {@see ReflectionProperty} + * @param non-empty-string $name The property name. + * @return ReflectionProperty A {@see ReflectionProperty} * @throws ReflectionException If no property exists by that name. */ #[Pure] @@ -260,7 +260,7 @@ public function getProperty(#[LanguageLevelTypeAware(['8.0' => 'string'], defaul * @param int|null $filter The optional filter, for filtering desired * property types. It's configured using the {@see ReflectionProperty} constants, * and defaults to all property types. - * @return ReflectionProperty[] + * @return list> */ #[Pure] #[TentativeType] @@ -270,8 +270,8 @@ public function getProperties(#[LanguageLevelTypeAware(['8.0' => 'int|null'], de * Gets a ReflectionClassConstant for a class's property * * @link https://php.net/manual/en/reflectionclass.getreflectionconstant.php - * @param string $name The class constant name. - * @return ReflectionClassConstant|false A {@see ReflectionClassConstant}. + * @param non-empty-string $name The class constant name. + * @return ReflectionClassConstant|false A {@see ReflectionClassConstant}. * @since 7.1 */ #[Pure] @@ -283,7 +283,7 @@ public function getReflectionConstant(string $name): ReflectionClassConstant|fal * * @link https://php.net/manual/en/reflectionclass.getreflectionconstants.php * @param int|null $filter [optional] allows the filtering of constants defined in a class by their visibility. Since 8.0. - * @return ReflectionClassConstant[] An array of ReflectionClassConstant objects. + * @return list> An array of ReflectionClassConstant objects. * @since 7.1 */ #[Pure] @@ -305,7 +305,7 @@ public function hasConstant(#[LanguageLevelTypeAware(['8.0' => 'string'], defaul * * @link https://php.net/manual/en/reflectionclass.getconstants.php * @param int|null $filter [optional] allows the filtering of constants defined in a class by their visibility. Since 8.0. - * @return array An array of constants, where the keys hold the name and + * @return array An array of constants, where the keys hold the name and * the values the value of the constants. */ #[Pure] @@ -316,7 +316,7 @@ public function getConstants(#[PhpStormStubsElementAvailable(from: '8.0')] ?int * Gets defined constant * * @link https://php.net/manual/en/reflectionclass.getconstant.php - * @param string $name Name of the constant. + * @param non-empty-string $name Name of the constant. * @return mixed|false Value of the constant with the name name. * Returns {@see false} if the constant was not found in the class. */ @@ -328,7 +328,7 @@ public function getConstant(#[LanguageLevelTypeAware(['8.0' => 'string'], defaul * Gets the interfaces * * @link https://php.net/manual/en/reflectionclass.getinterfaces.php - * @return ReflectionClass[] An associative array of interfaces, with keys as interface + * @return list An associative array of interfaces, with keys as interface * names and the array values as {@see ReflectionClass} objects. */ #[Pure] @@ -339,7 +339,7 @@ public function getInterfaces(): array {} * Gets the interface names * * @link https://php.net/manual/en/reflectionclass.getinterfacenames.php - * @return string[] A numerical array with interface names as the values. + * @return list A numerical array with interface names as the values. */ #[Pure] #[TentativeType] @@ -370,7 +370,7 @@ public function isInterface(): bool {} * Returns an array of traits used by this class * * @link https://php.net/manual/en/reflectionclass.gettraits.php - * @return ReflectionClass[] an array with trait names in keys and + * @return list an array with trait names in keys and * instances of trait's {@see ReflectionClass} in values. * @since 5.4 */ @@ -382,7 +382,7 @@ public function getTraits(): array {} * Returns an array of names of traits used by this class * * @link https://php.net/manual/en/reflectionclass.gettraitnames.php - * @return string[] An array with trait names in values. + * @return list An array with trait names in values. * Returns {@see null} in case of an error. * @since 5.4 */ @@ -394,7 +394,7 @@ public function getTraitNames(): array {} * Returns an array of trait aliases * * @link https://php.net/manual/en/reflectionclass.gettraitaliases.php - * @return string[] an array with new method names in keys and original + * @return array an array with new method names in keys and original * names (in the format "TraitName::original") in values. * Returns {@see null} in case of an error. * @since 5.4 @@ -469,7 +469,7 @@ public function isInstance(#[LanguageLevelTypeAware(['8.0' => 'object'], default * @link https://php.net/manual/en/reflectionclass.newinstance.php * @param mixed ...$args Accepts a variable number of arguments which are * passed to the class constructor, much like {@see call_user_func} - * @return T a new instance of the class. + * @return TReflectedClass a new instance of the class. * @throws ReflectionException if the class constructor is not public or if * the class does not have a constructor and the $args parameter contains * one or more parameters. @@ -480,7 +480,7 @@ public function newInstance(...$args) {} * Creates a new class instance without invoking the constructor. * * @link https://php.net/manual/en/reflectionclass.newinstancewithoutconstructor.php - * @return T a new instance of the class. + * @return TReflectedClass a new instance of the class. * @throws ReflectionException if the class is an internal class that * cannot be instantiated without invoking the constructor. In PHP 5.6.0 * onwards, this exception is limited only to internal classes that are final. @@ -494,7 +494,7 @@ public function newInstanceWithoutConstructor(): object {} * * @link https://php.net/manual/en/reflectionclass.newinstanceargs.php * @param array $args The parameters to be passed to the class constructor as an array. - * @return T|null a new instance of the class. + * @return TReflectedClass|null a new instance of the class. * @throws ReflectionException if the class constructor is not public or if * the class does not have a constructor and the $args parameter contains * one or more parameters. @@ -530,7 +530,7 @@ public function isSubclassOf(#[LanguageLevelTypeAware(['8.0' => 'ReflectionClass * Gets static properties * * @link https://php.net/manual/en/reflectionclass.getstaticproperties.php - * @return array|null The static properties, as an array where the keys hold + * @return array|null The static properties, as an array where the keys hold * the name and the values the value of the properties. */ #[Pure] @@ -542,7 +542,7 @@ public function getStaticProperties() {} * Gets static property value * * @link https://php.net/manual/en/reflectionclass.getstaticpropertyvalue.php - * @param string $name The name of the static property for which to return a value. + * @param non-empty-string $name The name of the static property for which to return a value. * @param mixed $default [optional] A default value to return in case the class does * not declare a static property with the given name. If the property does * not exist and this argument is omitted, a {@see ReflectionException} is thrown. @@ -559,7 +559,7 @@ public function getStaticPropertyValue( * Sets static property value * * @link https://php.net/manual/en/reflectionclass.setstaticpropertyvalue.php - * @param string $name Property name. + * @param non-empty-string $name Property name. * @param mixed $value New property value. * @return void No value is returned. */ @@ -573,7 +573,7 @@ public function setStaticPropertyValue( * Gets default properties * * @link https://php.net/manual/en/reflectionclass.getdefaultproperties.php - * @return mixed[] An array of default properties, with the key being the name + * @return array An array of default properties, with the key being the name * of the property and the value being the default value of the property * or {@see null} if the property doesn't have a default value. The function * does not distinguish between static and non static properties and does @@ -659,20 +659,20 @@ public function getNamespaceName(): string {} * Gets short name * * @link https://php.net/manual/en/reflectionclass.getshortname.php - * @return string The class short name. + * @return non-empty-string The class short name. */ #[Pure] #[TentativeType] public function getShortName(): string {} /** - * @template T + * @template TAttributeClass of Attribute * * Returns an array of class attributes. * - * @param class-string|null $name Name of an attribute class + * @param class-string|null $name Name of an attribute class * @param int $flags Сriteria by which the attribute is searched. - * @return ReflectionAttribute[] + * @return list> * @since 8.0 */ #[Pure] @@ -705,7 +705,7 @@ public function isEnum(): bool {} public function newLazyGhost(callable $initializer, int $options = 0): object {} /** - * @return T + * @return TReflectedClass * @since 8.4 */ public function newLazyProxy(callable $factory, int $options = 0): object {} diff --git a/Reflection/ReflectionClassConstant.php b/Reflection/ReflectionClassConstant.php index 6b6313358..82e29576f 100644 --- a/Reflection/ReflectionClassConstant.php +++ b/Reflection/ReflectionClassConstant.php @@ -12,18 +12,19 @@ * * @link https://www.php.net/manual/en/class.reflectionclassconstant.php * @since 7.1 + * @template TReflectedClass of object */ class ReflectionClassConstant implements Reflector { /** - * @var string Constant name, same as calling the {@see ReflectionClassConstant::getName()} method + * @var non-empty-string Constant name, same as calling the {@see ReflectionClassConstant::getName()} method */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] public $name; /** - * @var class-string Fully qualified class name where this constant was defined + * @var class-string Fully qualified class name where this constant was defined */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] @@ -65,8 +66,8 @@ class ReflectionClassConstant implements Reflector /** * ReflectionClassConstant constructor. * - * @param class-string|object $class Either a string containing the name of the class to reflect, or an object. - * @param string $constant The name of the class constant. + * @param class-string|TReflectedClass $class Either a string containing the name of the class to reflect, or an object. + * @param non-empty-string $constant The name of the class constant. * @since 7.1 * @link https://php.net/manual/en/reflectionclassconstant.construct.php */ @@ -123,7 +124,7 @@ public function getModifiers(): int {} * Get name of the constant * * @link https://php.net/manual/en/reflectionclassconstant.getname.php - * @return string Returns the constant's name. + * @return non-empty-string Returns the constant's name. * @since 7.1 */ #[Pure] @@ -184,13 +185,13 @@ public function isPublic(): bool {} public function __toString(): string {} /** - * @template T + * @template TAttributeClass of Attribute * * Returns an array of constant attributes. * - * @param class-string|null $name Name of an attribute class + * @param class-string|null $name Name of an attribute class * @param int $flags Сriteria by which the attribute is searched. - * @return ReflectionAttribute[] + * @return list> * @since 8.0 */ #[Pure] diff --git a/Reflection/ReflectionConstant.php b/Reflection/ReflectionConstant.php index e5afe6c4b..b35edd17b 100644 --- a/Reflection/ReflectionConstant.php +++ b/Reflection/ReflectionConstant.php @@ -36,6 +36,13 @@ public function getExtension(): ?ReflectionExtension {} public function getExtensionName(): string|false {} /** + * @template TAttributeClass of Attribute + * + * Returns an array of extension attributes. + * + * @param class-string|null $name Name of an attribute class + * @param int $flags Сriteria by which the attribute is searched. + * @return list> * @since 8.5 */ public function getAttributes(?string $name = null, int $flags = 0): array {} diff --git a/Reflection/ReflectionEnum.php b/Reflection/ReflectionEnum.php index 9e9de8531..a6e1ec18b 100644 --- a/Reflection/ReflectionEnum.php +++ b/Reflection/ReflectionEnum.php @@ -5,9 +5,13 @@ /** * @link https://php.net/manual/en/class.reflectionenum.php * @since 8.1 + * @template TReflectedClass of UnitEnum */ class ReflectionEnum extends ReflectionClass { + /** + * @param class-string|TReflectedClass $objectOrClass + */ public function __construct(object|string $objectOrClass) {} /** @@ -17,12 +21,13 @@ public function __construct(object|string $objectOrClass) {} public function hasCase(string $name): bool {} /** - * @return ReflectionEnumUnitCase[]|ReflectionEnumBackedCase[] + * @return (TReflectedClass is BackedEnum ? list> : list>) */ public function getCases(): array {} /** - * @return ReflectionEnumUnitCase|ReflectionEnumBackedCase + * @param non-empty-string $name + * @return (TReflectedClass is BackedEnum ? ReflectionEnumBackedCase : ReflectionEnumUnitCase) * @throws ReflectionException If no found single reflection object for the corresponding case */ public function getCase(string $name): ReflectionEnumUnitCase {} diff --git a/Reflection/ReflectionEnumBackedCase.php b/Reflection/ReflectionEnumBackedCase.php index d3fd7d8ab..fa3e1d339 100644 --- a/Reflection/ReflectionEnumBackedCase.php +++ b/Reflection/ReflectionEnumBackedCase.php @@ -5,9 +5,13 @@ /** * @link https://php.net/manual/en/class.reflectionenumbackedcase.php * @since 8.1 + * @template TReflectedClass of BackedEnum */ class ReflectionEnumBackedCase extends ReflectionEnumUnitCase { + /** + * @param class-string|TReflectedClass $class + */ public function __construct(object|string $class, string $constant) {} #[Pure] diff --git a/Reflection/ReflectionEnumUnitCase.php b/Reflection/ReflectionEnumUnitCase.php index 513da007d..13710f290 100644 --- a/Reflection/ReflectionEnumUnitCase.php +++ b/Reflection/ReflectionEnumUnitCase.php @@ -5,9 +5,13 @@ /** * @link https://php.net/manual/en/class.reflectionenumunitcase.php * @since 8.1 + * @template TReflectedClass of UnitEnum */ class ReflectionEnumUnitCase extends ReflectionClassConstant { + /** + * @param class-string|TReflectedClass $class + */ public function __construct(object|string $class, string $constant) {} #[Pure] diff --git a/Reflection/ReflectionFunction.php b/Reflection/ReflectionFunction.php index 657f99c97..c633fc9cc 100644 --- a/Reflection/ReflectionFunction.php +++ b/Reflection/ReflectionFunction.php @@ -16,7 +16,7 @@ class ReflectionFunction extends ReflectionFunctionAbstract { /** - * @var string Function name, same as calling the {@see ReflectionFunction::getName()} method + * @var non-empty-string Function name, same as calling the {@see ReflectionFunction::getName()} method */ #[Immutable] public $name; @@ -32,7 +32,7 @@ class ReflectionFunction extends ReflectionFunctionAbstract * Constructs a ReflectionFunction object * * @link https://php.net/manual/en/reflectionfunction.construct.php - * @param string|Closure $function The name of the function to reflect or a closure. + * @param non-empty-string|Closure $function The name of the function to reflect or a closure. * @throws ReflectionException if the function does not exist. */ public function __construct(#[LanguageLevelTypeAware(['8.0' => 'Closure|string'], default: '')] $function) {} @@ -87,7 +87,7 @@ public function invoke(#[LanguageLevelTypeAware(['8.0' => 'mixed'], default: '') * Invokes function args * * @link https://php.net/manual/en/reflectionfunction.invokeargs.php - * @param array $args The passed arguments to the function as an array, much + * @param list $args The passed arguments to the function as an array, much * like {@see call_user_func_array} works. * @return mixed the result of the invoked function */ diff --git a/Reflection/ReflectionFunctionAbstract.php b/Reflection/ReflectionFunctionAbstract.php index ed95b130e..0c0ae5995 100644 --- a/Reflection/ReflectionFunctionAbstract.php +++ b/Reflection/ReflectionFunctionAbstract.php @@ -15,7 +15,7 @@ abstract class ReflectionFunctionAbstract implements Reflector { /** - * @var string Name of the function, same as calling the {@see ReflectionFunctionAbstract::getName()} method + * @var non-empty-string Name of the function, same as calling the {@see ReflectionFunctionAbstract::getName()} method */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] @@ -197,7 +197,7 @@ public function getFileName(): string|false {} * Gets function name * * @link https://php.net/manual/en/reflectionfunctionabstract.getname.php - * @return string The name of the function. + * @return non-empty-string The name of the function. */ #[Pure] #[TentativeType] @@ -239,7 +239,7 @@ public function getNumberOfRequiredParameters(): int {} * Gets parameters * * @link https://php.net/manual/en/reflectionfunctionabstract.getparameters.php - * @return ReflectionParameter[] The parameters, as a ReflectionParameter objects. + * @return list The parameters, as a ReflectionParameter objects. */ #[Pure] #[TentativeType] @@ -316,13 +316,13 @@ public function returnsReference(): bool {} public function hasReturnType(): bool {} /** - * @template T + * @template TAttributeClass of Attribute * * Returns an array of function attributes. * - * @param class-string|null $name Name of an attribute class + * @param class-string|null $name Name of an attribute class * @param int $flags Сriteria by which the attribute is searched. - * @return ReflectionAttribute[] + * @return list> * @since 8.0 */ #[Pure] diff --git a/Reflection/ReflectionIntersectionType.php b/Reflection/ReflectionIntersectionType.php index c4a11013e..b95fa2d63 100644 --- a/Reflection/ReflectionIntersectionType.php +++ b/Reflection/ReflectionIntersectionType.php @@ -7,7 +7,7 @@ */ class ReflectionIntersectionType extends ReflectionType { - /** @return ReflectionType[] */ + /** @return list */ #[Pure] public function getTypes(): array {} } diff --git a/Reflection/ReflectionMethod.php b/Reflection/ReflectionMethod.php index a616666a3..fd2ec41dc 100644 --- a/Reflection/ReflectionMethod.php +++ b/Reflection/ReflectionMethod.php @@ -12,17 +12,18 @@ * information about a method. * * @link https://php.net/manual/en/class.reflectionmethod.php + * @template TReflectedClass of object */ class ReflectionMethod extends ReflectionFunctionAbstract { /** - * @var string Name of the method, same as calling the {@see ReflectionMethod::getName()} method + * @var non-empty-string Name of the method, same as calling the {@see ReflectionMethod::getName()} method */ #[Immutable] public $name; /** - * @var class-string Fully qualified class name where this method was defined + * @var class-string Fully qualified class name where this method was defined */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] @@ -68,10 +69,10 @@ class ReflectionMethod extends ReflectionFunctionAbstract * * * @link https://php.net/manual/en/reflectionmethod.construct.php - * @param string|object $objectOrMethod Classname, object + * @param non-empty-string|class-string|TReflectedClass $objectOrMethod Classname, object * (instance of the class) that contains the method or class name and * method name delimited by ::. - * @param string|null $method Name of the method if the first argument is a + * @param non-empty-string|null $method Name of the method if the first argument is a * classname or an object. * @throws ReflectionException if the class or method does not exist. */ diff --git a/Reflection/ReflectionNamedType.php b/Reflection/ReflectionNamedType.php index 073b58f99..19a170162 100644 --- a/Reflection/ReflectionNamedType.php +++ b/Reflection/ReflectionNamedType.php @@ -12,7 +12,7 @@ class ReflectionNamedType extends ReflectionType * Get the text of the type hint. * * @link https://php.net/manual/en/reflectionnamedtype.getname.php - * @return string Returns the text of the type hint. + * @return non-empty-string Returns the text of the type hint. * @since 7.1 */ #[Pure] diff --git a/Reflection/ReflectionObject.php b/Reflection/ReflectionObject.php index 7ddf19801..d295e621a 100644 --- a/Reflection/ReflectionObject.php +++ b/Reflection/ReflectionObject.php @@ -8,6 +8,8 @@ * information about an object. * * @link https://php.net/manual/en/class.reflectionobject.php + * @template TReflectedClass of object + * @extends ReflectionClass */ class ReflectionObject extends ReflectionClass { @@ -15,7 +17,7 @@ class ReflectionObject extends ReflectionClass * Constructs a ReflectionObject * * @link https://php.net/manual/en/reflectionobject.construct.php - * @param object $object An object instance. + * @param TReflectedClass $object An object instance. */ public function __construct(#[LanguageLevelTypeAware(['8.0' => 'object'], default: '')] $object) {} diff --git a/Reflection/ReflectionParameter.php b/Reflection/ReflectionParameter.php index 4bc5e607f..10db41d01 100644 --- a/Reflection/ReflectionParameter.php +++ b/Reflection/ReflectionParameter.php @@ -27,8 +27,8 @@ class ReflectionParameter implements Reflector * * @link https://php.net/manual/en/reflectionparameter.construct.php * @param callable $function The function to reflect parameters from. - * @param string|int $param Either an integer specifying the position - * of the parameter (starting with zero), or a the parameter name as string. + * @param non-empty-string|int $param Either an integer specifying the position + * of the parameter (starting with zero), or the parameter name as a string. * @throws ReflectionException if the function or parameter does not exist. */ public function __construct($function, #[LanguageLevelTypeAware(['8.0' => 'string|int'], default: '')] $param) {} @@ -37,8 +37,8 @@ public function __construct($function, #[LanguageLevelTypeAware(['8.0' => 'strin * Exports * * @link https://php.net/manual/en/reflectionparameter.export.php - * @param string $function The function name. - * @param string $parameter The parameter name. + * @param non-empty-string $function The function name. + * @param non-empty-string $parameter The parameter name. * @param bool $return Setting to {@see true} will return the export, * as opposed to emitting it. Setting to {@see false} (the default) will do the * opposite. @@ -61,7 +61,7 @@ public function __toString(): string {} * Gets parameter name * * @link https://php.net/manual/en/reflectionparameter.getname.php - * @return string The name of the reflected parameter. + * @return non-empty-string The name of the reflected parameter. */ #[Pure] #[TentativeType] @@ -81,12 +81,12 @@ public function isPassedByReference(): bool {} * Returns whether this parameter can be passed by value * * @link https://php.net/manual/en/reflectionparameter.canbepassedbyvalue.php - * @return bool|null {@see true} if the parameter can be passed by value, {@see false} otherwise. + * @return bool|null {@see true} if the parameter can be passed by value, {@see false} otherwise, or {@see null} on error. * Returns {@see null} in case of an error. * @since 5.4 */ #[TentativeType] - public function canBePassedByValue(): bool {} + public function canBePassedByValue(): ?bool {} /** * Gets declaring function @@ -277,13 +277,13 @@ public function isVariadic(): bool {} public function isPromoted(): bool {} /** - * @template T + * @template TAttributeClass of Attribute * * Returns an array of parameter attributes. * - * @param class-string|null $name Name of an attribute class + * @param class-string|null $name Name of an attribute class * @param int $flags Сriteria by which the attribute is searched. - * @return ReflectionAttribute[] + * @return list> * @since 8.0 */ #[Pure] diff --git a/Reflection/ReflectionProperty.php b/Reflection/ReflectionProperty.php index cefe1c35f..0c4ba2285 100644 --- a/Reflection/ReflectionProperty.php +++ b/Reflection/ReflectionProperty.php @@ -12,6 +12,7 @@ * properties. * * @link https://php.net/manual/en/class.reflectionproperty.php + * @template TReflectedClass of object */ class ReflectionProperty implements Reflector { @@ -26,14 +27,14 @@ class ReflectionProperty implements Reflector public const IS_VIRTUAL = 512; /** - * @var string Name of the property, same as calling the {@see ReflectionProperty::getName()} method + * @var non-empty-string Name of the property, same as calling the {@see ReflectionProperty::getName()} method */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] public $name; /** - * @var class-string Fully qualified class name where this property was defined + * @var class-string Fully qualified class name where this property was defined */ #[Immutable] #[LanguageLevelTypeAware(['8.1' => 'string'], default: '')] @@ -91,8 +92,8 @@ class ReflectionProperty implements Reflector * Construct a ReflectionProperty object * * @link https://php.net/manual/en/reflectionproperty.construct.php - * @param class-string|object $class The class name, that contains the property. - * @param string $property The name of the property being reflected. + * @param class-string|TReflectedClass $class The class name, that contains the property. + * @param non-empty-string $property The name of the property being reflected. * @throws ReflectionException if the class or property does not exist. */ public function __construct( @@ -128,7 +129,7 @@ public function __toString(): string {} * Gets property name * * @link https://php.net/manual/en/reflectionproperty.getname.php - * @return string The name of the reflected property. + * @return non-empty-string The name of the reflected property. */ #[Pure] #[TentativeType] @@ -353,13 +354,13 @@ public function hasDefaultValue(): bool {} public function getDefaultValue(): mixed {} /** - * @template T + * @template TAttributeClass of Attribute * * Returns an array of property attributes. * - * @param class-string|null $name Name of an attribute class + * @param class-string|null $name Name of an attribute class * @param int $flags Сriteria by which the attribute is searched. - * @return ReflectionAttribute[] + * @return list> * @since 8.0 */ #[Pure] diff --git a/tests/Model/StubsContainer.php b/tests/Model/StubsContainer.php index a1c8f1a38..a0c616bdc 100644 --- a/tests/Model/StubsContainer.php +++ b/tests/Model/StubsContainer.php @@ -270,7 +270,7 @@ public function getEnumByHash(string $hash) } /** - * @param true $shouldSuitCurrentLanguageVersion + * @param true $shouldSuitCurrentPhpVersion * @return PHPClass[] */ public function getCoreClasses($shouldSuitCurrentPhpVersion = true)