1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00

Improved Reflection stubs

ReflectionParameter::getPosition() is non-negative-int.
ReflectionMethod name property is always non-empty-string.
ReflectionAttribute::getTarget() returns Attribute::TARGET_* instead of int-mask. Even for attributes of promoted properties (https://3v4l.org/rpM1t).
*::getAttributes() always returns a list (https://3v4l.org/LYAMb).
This commit is contained in:
Valentin Udaltsov 2023-08-08 18:08:05 +03:00
parent 4a5dbcaebc
commit 07a64f6894
3 changed files with 7 additions and 7 deletions

View File

@ -10631,7 +10631,7 @@ return [
'ReflectionParameter::getDefaultValue' => ['mixed'], 'ReflectionParameter::getDefaultValue' => ['mixed'],
'ReflectionParameter::getDefaultValueConstantName' => ['?string'], 'ReflectionParameter::getDefaultValueConstantName' => ['?string'],
'ReflectionParameter::getName' => ['string'], 'ReflectionParameter::getName' => ['string'],
'ReflectionParameter::getPosition' => ['int'], 'ReflectionParameter::getPosition' => ['int<0, max>'],
'ReflectionParameter::getType' => ['?ReflectionType'], 'ReflectionParameter::getType' => ['?ReflectionType'],
'ReflectionParameter::hasType' => ['bool'], 'ReflectionParameter::hasType' => ['bool'],
'ReflectionParameter::isArray' => ['bool'], 'ReflectionParameter::isArray' => ['bool'],

View File

@ -28,7 +28,7 @@ class ReflectionAttribute
/** /**
* @psalm-pure * @psalm-pure
* @return int-mask-of<Attribute::TARGET_*> * @return Attribute::TARGET_*
*/ */
public function getTarget() : int public function getTarget() : int
{ {

View File

@ -416,7 +416,7 @@ abstract class ReflectionFunctionAbstract implements Reflector
* @since 8.0 * @since 8.0
* @template TClass as object * @template TClass as object
* @param class-string<TClass>|null $name * @param class-string<TClass>|null $name
* @return ($name is null ? array<ReflectionAttribute<object>> : array<ReflectionAttribute<TClass>>) * @return ($name is null ? list<ReflectionAttribute<object>> : list<ReflectionAttribute<TClass>>)
*/ */
public function getAttributes(?string $name = null, int $flags = 0): array {} public function getAttributes(?string $name = null, int $flags = 0): array {}
} }
@ -463,7 +463,7 @@ class ReflectionProperty implements Reflector
* @since 8.0 * @since 8.0
* @template TClass as object * @template TClass as object
* @param class-string<TClass>|null $name * @param class-string<TClass>|null $name
* @return ($name is null ? array<ReflectionAttribute<object>> : array<ReflectionAttribute<TClass>>) * @return ($name is null ? list<ReflectionAttribute<object>> : list<ReflectionAttribute<TClass>>)
*/ */
public function getAttributes(?string $name = null, int $flags = 0): array {} public function getAttributes(?string $name = null, int $flags = 0): array {}
@ -540,7 +540,7 @@ class ReflectionProperty implements Reflector
class ReflectionMethod extends ReflectionFunctionAbstract class ReflectionMethod extends ReflectionFunctionAbstract
{ {
/** /**
* @var string * @var non-empty-string
* @readonly * @readonly
*/ */
public $name; public $name;
@ -599,7 +599,7 @@ class ReflectionClassConstant implements Reflector
* @since 8.0 * @since 8.0
* @template TClass as object * @template TClass as object
* @param class-string<TClass>|null $name * @param class-string<TClass>|null $name
* @return ($name is null ? array<ReflectionAttribute<object>> : array<ReflectionAttribute<TClass>>) * @return ($name is null ? list<ReflectionAttribute<object>> : list<ReflectionAttribute<TClass>>)
*/ */
public function getAttributes(?string $name = null, int $flags = 0): array {} public function getAttributes(?string $name = null, int $flags = 0): array {}
@ -635,7 +635,7 @@ class ReflectionParameter implements Reflector {
* @since 8.0 * @since 8.0
* @template TClass as object * @template TClass as object
* @param class-string<TClass>|null $name * @param class-string<TClass>|null $name
* @return ($name is null ? array<ReflectionAttribute<object>> : array<ReflectionAttribute<TClass>>) * @return ($name is null ? list<ReflectionAttribute<object>> : list<ReflectionAttribute<TClass>>)
*/ */
public function getAttributes(?string $name = null, int $flags = 0): array {} public function getAttributes(?string $name = null, int $flags = 0): array {}