From 41256c74d1049c5cccd718a78b3ffe9890f7f396 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sun, 28 Nov 2021 11:41:43 +0200 Subject: [PATCH] Added enum-related stubs and callmaps Fixes vimeo/psalm#6430 --- dictionaries/CallMap.php | 11 ++++++++++- dictionaries/CallMap_81_delta.php | 9 +++++++++ stubs/Php81.phpstub | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dictionaries/CallMap.php b/dictionaries/CallMap.php index 075541f5e9f..e2bb1110424 100644 --- a/dictionaries/CallMap.php +++ b/dictionaries/CallMap.php @@ -2518,6 +2518,7 @@ 'enchant_dict_store_replacement' => ['void', 'dictionary'=>'resource', 'misspelled'=>'string', 'correct'=>'string'], 'enchant_dict_suggest' => ['array', 'dictionary'=>'resource', 'word'=>'string'], 'end' => ['mixed|false', '&r_array'=>'array|object'], +'enum_exists' => ['bool', 'class' => 'class-string', 'autoload=' => 'bool'], 'Error::__clone' => ['void'], 'Error::__construct' => ['void', 'message='=>'string', 'code='=>'int', 'previous='=>'?Throwable|?Error'], 'Error::__toString' => ['string'], @@ -8406,7 +8407,7 @@ 'mysqli::get_warnings' => ['mysqli_warning'], 'mysqli::init' => ['false|null'], 'mysqli::kill' => ['bool', 'process_id'=>'int'], -'mysqli::more_results' => ['bool'], +'mysqli::more_results' => ['bool'], 'mysqli::multi_query' => ['bool', 'query'=>'string'], 'mysqli::next_result' => ['bool'], 'mysqli::options' => ['bool', 'option'=>'int', 'value'=>'string|int'], @@ -11369,6 +11370,14 @@ 'ReflectionClassConstant::isPrivate' => ['bool'], 'ReflectionClassConstant::isProtected' => ['bool'], 'ReflectionClassConstant::isPublic' => ['bool'], +'ReflectionEnum::getBackingType' => ['?ReflectionType'], +'ReflectionEnum::getCase' => ['ReflectionEnumUnitCase', 'name' => 'string'], +'ReflectionEnum::getCases' => ['list'], +'ReflectionEnum::hasCase' => ['bool', 'name' => 'string'], +'ReflectionEnum::isBacked' => ['bool'], +'ReflectionEnumUnitCase::getEnum' => ['ReflectionEnum'], +'ReflectionEnumUnitCase::getValue' => ['UnitEnum'], +'ReflectionEnumBackedCase::getBackingValue' => ['string|int'], 'ReflectionExtension::__clone' => ['void'], 'ReflectionExtension::__construct' => ['void', 'name'=>'string'], 'ReflectionExtension::__toString' => ['string'], diff --git a/dictionaries/CallMap_81_delta.php b/dictionaries/CallMap_81_delta.php index 58d305a2382..efa975bd3fc 100644 --- a/dictionaries/CallMap_81_delta.php +++ b/dictionaries/CallMap_81_delta.php @@ -17,6 +17,7 @@ return [ 'added' => [ 'array_is_list' => ['bool', 'array' => 'array'], + 'enum_exists' => ['bool', 'class' => 'class-string', 'autoload=' => 'bool'], 'fsync' => ['bool', 'stream' => 'resource'], 'fdatasync' => ['bool', 'stream' => 'resource'], 'imageavif' => ['bool', 'image'=>'GdImage', 'file='=>'resource|string|null', 'quality='=>'int', 'speed='=>'int'], @@ -36,6 +37,14 @@ 'Fiber::getCurrent' => ['?self'], 'Fiber::suspend' => ['mixed', 'value='=>'null|mixed'], 'FiberError::__construct' => ['void'], + 'ReflectionEnum::getBackingType' => ['?ReflectionType'], + 'ReflectionEnum::getCase' => ['ReflectionEnumUnitCase', 'name' => 'string'], + 'ReflectionEnum::getCases' => ['list'], + 'ReflectionEnum::hasCase' => ['bool', 'name' => 'string'], + 'ReflectionEnum::isBacked' => ['bool'], + 'ReflectionEnumUnitCase::getEnum' => ['ReflectionEnum'], + 'ReflectionEnumUnitCase::getValue' => ['UnitEnum'], + 'ReflectionEnumBackedCase::getBackingValue' => ['string|int'], ], 'changed' => [ diff --git a/stubs/Php81.phpstub b/stubs/Php81.phpstub index 3a1937ae81f..7bf17a73bca 100644 --- a/stubs/Php81.phpstub +++ b/stubs/Php81.phpstub @@ -14,6 +14,27 @@ namespace { public static function from(string|int $value): static; public static function tryFrom(string|int $value): ?static; } + + class ReflectionEnum extends ReflectionClass implements Reflector + { + public function getBackingType(): ?ReflectionType; + public function getCase(string $name): ReflectionEnumUnitCase; + /** @return list */ + public function getCases(): array; + public function hasCase(string $name): bool; + public function isBacked(): bool; + } + + class ReflectionEnumUnitCase extends ReflectionClassConstant implements Reflector + { + public function getEnum(): ReflectionEnum; + public function getValue(): UnitEnum; + } + + class ReflectionEnumBackedCase extends ReflectionEnumUnitCase implements Reflector + { + public function getBackingValue(): int|string; + } } namespace FTP {