-
-
Notifications
You must be signed in to change notification settings - Fork 934
Closed
Labels
Description
Feature request
- Remove built-in type-specifying extensions in favour of stubs: https://github.com/phpstan/phpstan-src/tree/1.9.x/src/Type/Php (a nicer list is here https://apiref.phpstan.org/1.9.x/PHPStan.Type.FunctionTypeSpecifyingExtension.html)
- An interesting gotcha here is that if you remove an extension for a function mentioned here https://github.com/phpstan/phpstan-src/blob/1.9.x/src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php without adding a stub, PHPStan ends in an infinite recursion. But after adding a
@phpstan-assertstub it's fine again. This might be worth investigation and maybe fixing it.
- An interesting gotcha here is that if you remove an extension for a function mentioned here https://github.com/phpstan/phpstan-src/blob/1.9.x/src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php without adding a stub, PHPStan ends in an infinite recursion. But after adding a
- Maybe we can simplify phpstan-phpunit, phpstan-beberlei-assert, phpstan-webmozart-assert since these libraries already have
@psalm-assertannotations.- BUT: It already happened that PHPStan extension was more correct and precise than these annotations so we need to keep the tests
- BUT: We need to investigate which version of these libraries added those annotations. I'd say if it's longer than three years we can safely remove redundant extensions, otherwise not.
- We can definitely remove extensions for new methods in these libraries that were already added with those assert annotations.
UnionTypeMethodReflection::getAssertions()needs to be fixed. The logic to compute which annotations to use might be non-trivial.IntersectionTypeMethodReflection::getAssertions()needs to be fixed. The logic to compute which annotations to use might be non-trivial.- Documentation at https://phpstan.org/writing-php-code/narrowing-types#custom-type-checking-functions-and-methods