Modify functionMap and add __benevolent<>#2986
Conversation
|
You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x. |
| 'floatval' => ['float', 'var'=>'scalar|array|resource|null'], | ||
| 'flock' => ['bool', 'fp'=>'resource', 'operation'=>'int', '&w_wouldblock='=>'int'], | ||
| 'floor' => ['float|false', 'number'=>'float'], | ||
| 'floor' => ['__benevolent<float|false>', 'number'=>'float'], |
There was a problem hiding this comment.
Same as RoundFunctionReturnTypeExtension.
phpstan-src/src/Type/Php/RoundFunctionReturnTypeExtension.php
Lines 48 to 56 in f51d90c
| 'get_headers' => ['array|false', 'url'=>'string', 'format='=>'int', 'context='=>'resource'], | ||
| 'get_html_translation_table' => ['array', 'table='=>'int', 'flags='=>'int', 'encoding='=>'string'], | ||
| 'get_include_path' => ['string|false'], | ||
| 'get_include_path' => ['__benevolent<string|false>'], |
There was a problem hiding this comment.
Since the situation where the ini include_path entry does not exist is an abnormal situation, it seems that __benevolent<> can be added.
| 'memory_get_peak_usage' => ['int', 'real_usage='=>'bool'], | ||
| 'memory_get_usage' => ['int', 'real_usage='=>'bool'], | ||
| 'memory_get_peak_usage' => ['positive-int', 'real_usage='=>'bool'], | ||
| 'memory_get_usage' => ['positive-int', 'real_usage='=>'bool'], |
There was a problem hiding this comment.
These functions return only positive values.
https://3v4l.org/ZTQKN
| 'ming_useswfversion' => ['void', 'version'=>'int'], | ||
| 'mkdir' => ['bool', 'pathname'=>'string', 'mode='=>'int', 'recursive='=>'bool', 'context='=>'resource'], | ||
| 'mktime' => ['int|false', 'hour='=>'int', 'min='=>'int', 'sec='=>'int', 'mon='=>'int', 'day='=>'int', 'year='=>'int'], | ||
| 'mktime' => ['__benevolent<int|false>', 'hour='=>'int', 'min='=>'int', 'sec='=>'int', 'mon='=>'int', 'day='=>'int', 'year='=>'int'], |
There was a problem hiding this comment.
This function returns false only when it receives a value outside the integer range.
PHP Manual says:
mktime()returns the Unix timestamp of the arguments given, or false if the timestamp doesn't fit in a PHP integer.
It seems that even if PHP_INT_MAX is passed for all parameters, this value will never be exceeded.
https://3v4l.org/dnSu2
| $defaultReturnType = new BenevolentUnionType([ | ||
| new FloatType(), | ||
| new ConstantBooleanType(false), | ||
| ]); |
There was a problem hiding this comment.
This extension change is unnecessary, but it removes the duplicate definition of the type with functionMap.
There was a problem hiding this comment.
just stumbled over
phpstan-src/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php
Lines 39 to 41 in cbdc933
|
Thank you, changes make sense 😊 |
Add
__benevolent<>to functions whose documentation says "return false", which return false when passed a parameter of the wrong type, or which do not return false upon normal use.Modify the functionMap for other functions, including those already covered by DynamicFunctionReturnTypeExtension.