Roave / BetterReflection

:crystal_ball: Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.
MIT License
1.18k stars 131 forks source link

Fix `ReflectionEnum::newInstance()` return type #1379

Closed ondrejmirtes closed 10 months ago

ondrejmirtes commented 10 months ago

PHP does not complain about this (because parent has object return type) but it's wrong. I found out about it after introducing generics to ReflectionEnum: https://github.com/phpstan/phpstan-src/commit/9ce8faf53c7a78c7887a2c33f9d34944605d6aae

 ------ ------------------------------------------------------------------------- 
  Line   src/Reflection/Adapter/ReflectionEnum.php                                
 ------ ------------------------------------------------------------------------- 
  364    Return type                                                              
         (Roave\BetterReflection\Reflection\Adapter\ReflectionEnum) of method     
         Roave\BetterReflection\Reflection\Adapter\ReflectionEnum::newInstance()  
         should be compatible with return type (UnitEnum) of method               
         ReflectionClass<UnitEnum>::newInstance()                                 
 ------ ------------------------------------------------------------------------- 
Ocramius commented 10 months ago

Wait, did this pass before because self is a subtype of object? Sounds like we never call this API in our tests? 🤔

ondrejmirtes commented 10 months ago

@Ocramius It's fine even when called because the method always throws...

Ocramius commented 10 months ago

Waiting for CI, then shipping this 👍

Ocramius commented 10 months ago

Thanks @ondrejmirtes!