-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify functionMap and add __benevolent<> #2986
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -933,7 +933,7 @@ | |
'CallbackFilterIterator::next' => ['void'], | ||
'CallbackFilterIterator::rewind' => ['void'], | ||
'CallbackFilterIterator::valid' => ['bool'], | ||
'ceil' => ['float|false', 'number'=>'float'], | ||
'ceil' => ['__benevolent<float|false>', 'number'=>'float'], | ||
'chdb::__construct' => ['void', 'pathname'=>'string'], | ||
'chdb::get' => ['string', 'key'=>'string'], | ||
'chdb_create' => ['bool', 'pathname'=>'string', 'data'=>'array'], | ||
|
@@ -2991,7 +2991,7 @@ | |
'finfo_set_flags' => ['bool', 'finfo'=>'resource', 'options'=>'int'], | ||
'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'], | ||
'flush' => ['void'], | ||
'fmod' => ['float', 'x'=>'float', 'y'=>'float'], | ||
'fnmatch' => ['bool', 'pattern'=>'string', 'filename'=>'string', 'flags='=>'int'], | ||
|
@@ -3311,7 +3311,7 @@ | |
'get_extension_funcs' => ['list<callable-string>|false', 'extension_name'=>'string'], | ||
'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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the situation where the ini |
||
'get_included_files' => ['list<string>'], | ||
'get_loaded_extensions' => ['list<string>', 'zend_extensions='=>'bool'], | ||
'get_magic_quotes_gpc' => ['false'], | ||
|
@@ -6494,8 +6494,8 @@ | |
'MemcachePool::set' => ['bool', 'key'=>'string', 'var'=>'mixed', 'flag='=>'int', 'expire='=>'int'], | ||
'MemcachePool::setCompressThreshold' => ['bool', 'threshold'=>'int', 'min_savings='=>'float'], | ||
'MemcachePool::setServerParams' => ['bool', 'host'=>'string', 'port='=>'int', 'timeout='=>'int', 'retry_interval='=>'int', 'status='=>'bool', 'failure_callback='=>'callable'], | ||
'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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions return only positive values. |
||
'MessageFormatter::__construct' => ['void', 'locale'=>'string', 'pattern'=>'string'], | ||
'MessageFormatter::create' => ['MessageFormatter', 'locale'=>'string', 'pattern'=>'string'], | ||
'MessageFormatter::format' => ['false|string', 'args'=>'array'], | ||
|
@@ -6525,7 +6525,7 @@ | |
'ming_useconstants' => ['void', 'use'=>'int'], | ||
'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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function returns false only when it receives a value outside the integer range. PHP Manual says:
It seems that even if |
||
'money_format' => ['string', 'format'=>'string', 'value'=>'float'], | ||
'Mongo::__construct' => ['void', 'server='=>'string', 'options='=>'array', 'driver_options='=>'array'], | ||
'Mongo::__get' => ['MongoDB', 'dbname'=>'string'], | ||
|
@@ -8962,10 +8962,10 @@ | |
'phdfs::tell' => ['int', 'path'=>'string'], | ||
'phdfs::write' => ['bool', 'path'=>'string', 'buffer'=>'string', 'mode='=>'string'], | ||
'php_check_syntax' => ['bool', 'filename'=>'string', 'error_message='=>'string'], | ||
'php_ini_loaded_file' => ['string|false'], | ||
'php_ini_loaded_file' => ['non-empty-string|false'], | ||
'php_ini_scanned_files' => ['string|false'], | ||
'php_logo_guid' => ['string'], | ||
'php_sapi_name' => ['string|false'], | ||
'php_sapi_name' => ['__benevolent<non-empty-string|false>'], | ||
'php_strip_whitespace' => ['string', 'file_name'=>'string'], | ||
'php_uname' => ['string', 'mode='=>'string'], | ||
'php_user_filter::filter' => ['int', 'in'=>'resource', 'out'=>'resource', '&rw_consumed'=>'int', 'closing'=>'bool'], | ||
|
@@ -10182,7 +10182,7 @@ | |
'rewind' => ['bool', 'fp'=>'resource'], | ||
'rewinddir' => ['null|false', 'dir_handle='=>'resource'], | ||
'rmdir' => ['bool', 'dirname'=>'string', 'context='=>'resource'], | ||
'round' => ['float|false', 'number'=>'float', 'precision='=>'int', 'mode='=>'1|2|3|4'], | ||
'round' => ['__benevolent<float|false>', 'number'=>'float', 'precision='=>'int', 'mode='=>'1|2|3|4'], | ||
'rpm_close' => ['bool', 'rpmr'=>'resource'], | ||
'rpm_get_tag' => ['mixed', 'rpmr'=>'resource', 'tagnum'=>'int'], | ||
'rpm_is_valid' => ['bool', 'filename'=>'string'], | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6,7 +6,6 @@ | |||||||
use PHPStan\Analyser\Scope; | ||||||||
use PHPStan\Php\PhpVersion; | ||||||||
use PHPStan\Reflection\FunctionReflection; | ||||||||
use PHPStan\Type\BenevolentUnionType; | ||||||||
use PHPStan\Type\Constant\ConstantBooleanType; | ||||||||
use PHPStan\Type\DynamicFunctionReturnTypeExtension; | ||||||||
use PHPStan\Type\FloatType; | ||||||||
|
@@ -39,21 +38,18 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo | |||||||
); | ||||||||
} | ||||||||
|
||||||||
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type | ||||||||
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type | ||||||||
{ | ||||||||
// PHP 7 can return either a float or false. | ||||||||
// PHP 8 can either return a float or fatal. | ||||||||
$defaultReturnType = null; | ||||||||
|
||||||||
if ($this->phpVersion->hasStricterRoundFunctions()) { | ||||||||
// PHP 8 fatals with a missing parameter. | ||||||||
$noArgsReturnType = new NeverType(true); | ||||||||
// PHP 8 can either return a float or fatal. | ||||||||
$defaultReturnType = new FloatType(); | ||||||||
} else { | ||||||||
// PHP 7 returns null with a missing parameter. | ||||||||
$noArgsReturnType = new NullType(); | ||||||||
// PHP 7 can return either a float or false. | ||||||||
$defaultReturnType = new BenevolentUnionType([ | ||||||||
new FloatType(), | ||||||||
new ConstantBooleanType(false), | ||||||||
]); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extension change is unnecessary, but it removes the duplicate definition of the type with functionMap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just stumbled over phpstan-src/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php Lines 39 to 41 in cbdc933
|
||||||||
} | ||||||||
|
||||||||
if (count($functionCall->getArgs()) < 1) { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as
RoundFunctionReturnTypeExtension
.phpstan-src/src/Type/Php/RoundFunctionReturnTypeExtension.php
Lines 48 to 56 in f51d90c