Implements BackedEnumFromDynamicStaticMethodThrowTypeExtension#4156
Implements BackedEnumFromDynamicStaticMethodThrowTypeExtension#4156VincentLanglet wants to merge 1 commit intophpstan:2.1.xfrom
Conversation
8746ed7 to
105dc08
Compare
105dc08 to
33866c1
Compare
ondrejmirtes
left a comment
There was a problem hiding this comment.
I really don't want people to discourage from defensive code. I don't want to report an error when someone catches an exception because the argument type is only guarded with a PHPDoc for example.
| return $methodReflection->getThrowType(); | ||
| } | ||
|
|
||
| $valueType = $scope->getType($arguments[0]->value); |
If I use This is the same than DynamicReturnTypeExtension which remove
Shouldn't it be at least conditioned by Or maybe but what I try to avoid is the error Can't the DynamicMethodThrowTypeExtension return a "BenevolentThrowType" then ? Something like an unchecked exception or an implicit throw point ? |
|
Friendly ping @ondrejmirtes Cf my comment #4156 (comment) I dunno how to move on this PR. If I use the nativeType as asked
Moreover I feel like writing is kinda weird, because it's the purpose of the method |
33866c1 to
843387f
Compare
|
I don't think the mutant is relevant because the whole if could be removed since there is later a check It's just an early return to reduce the computation. |
843387f to
c8c0173
Compare
|
Hi, I don't want to move on with this because I don't want to report dead catch for the following code: /** @param 1|2|3 $i */
public function doFoo($i): void
{
try { IntBackedEnum::from($i); } catch (\Throwable $t) {}
}Defensive code is good! |
I feel like if you want to write this, you should write instead I have trouble to see any difference between your example and this one I think others DynamicMethodExtension are working with |
Closes phpstan/phpstan#13297
Currently, even doing a simple
Enum::from(1)where1is a value valid, reports missing@throwsphpdoc.