From 035931029b105ec89d27461b8c0237e9ed8e4db9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 13:58:37 +0100 Subject: [PATCH 1/4] Refine `*strlen()` return type to exclude negative integers --- resources/functionMap.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index 9a29b02e0a..35781a719d 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -3638,7 +3638,7 @@ 'grapheme_extract' => ['string|false', 'str'=>'string', 'size'=>'int', 'extract_type='=>'int', 'start='=>'int', '&w_next='=>'int'], 'grapheme_stripos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'], 'grapheme_stristr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool'], -'grapheme_strlen' => ['int|false', 'str'=>'string'], +'grapheme_strlen' => ['0|positive-int|false', 'str'=>'string'], 'grapheme_strpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'], 'grapheme_strripos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'], 'grapheme_strrpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'], @@ -4448,7 +4448,7 @@ 'iconv_mime_decode_headers' => ['array|false', 'headers'=>'string', 'mode='=>'int', 'charset='=>'string'], 'iconv_mime_encode' => ['string|false', 'field_name'=>'string', 'field_value'=>'string', 'preference='=>'array'], 'iconv_set_encoding' => ['bool', 'type'=>'string', 'charset'=>'string'], -'iconv_strlen' => ['int|false', 'str'=>'string', 'charset='=>'string'], +'iconv_strlen' => ['0|positive-int|false', 'str'=>'string', 'charset='=>'string'], 'iconv_strpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'charset='=>'string'], 'iconv_strrpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'charset='=>'string'], 'iconv_substr' => ['string|false', 'str'=>'string', 'offset'=>'int', 'length='=>'int', 'charset='=>'string'], @@ -6347,7 +6347,7 @@ 'mb_strimwidth' => ['string', 'str'=>'string', 'start'=>'int', 'width'=>'int', 'trimmarker='=>'string', 'encoding='=>'string'], 'mb_stripos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'], 'mb_stristr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'], -'mb_strlen' => ['int|false', 'str'=>'string', 'encoding='=>'string'], +'mb_strlen' => ['0|positive-int|false', 'str'=>'string', 'encoding='=>'string'], 'mb_strpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'], 'mb_strrchr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'], 'mb_strrichr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'], @@ -9395,7 +9395,7 @@ 'Redis::sRem' => ['int', 'key'=>'string', 'member1'=>'string', '...other_members='=>'string'], 'Redis::sRemove' => ['int', 'key'=>'string', 'member1'=>'string', '...other_members='=>'string'], 'Redis::sScan' => ['array|bool', 'key'=>'string', '&iterator'=>'int', 'pattern='=>'string', 'count='=>'int'], -'Redis::strLen' => ['int', 'key'=>'string'], +'Redis::strLen' => ['0|positive-int', 'key'=>'string'], 'Redis::subscribe' => ['mixed|null', 'channels'=>'array', 'callback'=>'string|array'], 'Redis::substr' => ['', 'key'=>'string', 'start'=>'int', 'end'=>'int'], 'Redis::sUnion' => ['array', 'key'=>'string', '...other_keys='=>'string'], From 13abf0108f2e391e80165cdf0181c2fbf27e53a3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 17:49:14 +0100 Subject: [PATCH 2/4] fix tests --- tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index f49e371de0..1ad6c86903 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -5302,15 +5302,15 @@ public function dataFunctions(): array '$versionCompare8', ], [ - 'int', + 'int<0, max>', '$mbStrlenWithoutEncoding', ], [ - 'int', + 'int<0, max>', '$mbStrlenWithValidEncoding', ], [ - 'int', + 'int<0, max>', '$mbStrlenWithValidEncodingAlias', ], [ @@ -5318,11 +5318,11 @@ public function dataFunctions(): array '$mbStrlenWithInvalidEncoding', ], [ - PHP_VERSION_ID < 80000 ? 'int|false' : 'int', + PHP_VERSION_ID < 80000 ? 'int<0, max>|false' : 'int', '$mbStrlenWithValidAndInvalidEncoding', ], [ - PHP_VERSION_ID < 80000 ? 'int|false' : 'int', + PHP_VERSION_ID < 80000 ? 'int<0, max>|false' : 'int', '$mbStrlenWithUnknownEncoding', ], [ From 1a9c69faad71147b2ca42cd558d0a64359095784 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 18:03:34 +0100 Subject: [PATCH 3/4] Revert "fix tests" This reverts commit 13abf0108f2e391e80165cdf0181c2fbf27e53a3. --- tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 1ad6c86903..f49e371de0 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -5302,15 +5302,15 @@ public function dataFunctions(): array '$versionCompare8', ], [ - 'int<0, max>', + 'int', '$mbStrlenWithoutEncoding', ], [ - 'int<0, max>', + 'int', '$mbStrlenWithValidEncoding', ], [ - 'int<0, max>', + 'int', '$mbStrlenWithValidEncodingAlias', ], [ @@ -5318,11 +5318,11 @@ public function dataFunctions(): array '$mbStrlenWithInvalidEncoding', ], [ - PHP_VERSION_ID < 80000 ? 'int<0, max>|false' : 'int', + PHP_VERSION_ID < 80000 ? 'int|false' : 'int', '$mbStrlenWithValidAndInvalidEncoding', ], [ - PHP_VERSION_ID < 80000 ? 'int<0, max>|false' : 'int', + PHP_VERSION_ID < 80000 ? 'int|false' : 'int', '$mbStrlenWithUnknownEncoding', ], [ From 2316a9f716d9c6b484e195ca9a15d00cd9d399ea Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 26 Jan 2022 18:03:43 +0100 Subject: [PATCH 4/4] revert mb_strlen --- resources/functionMap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index 35781a719d..6ac2e93c63 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -6347,7 +6347,7 @@ 'mb_strimwidth' => ['string', 'str'=>'string', 'start'=>'int', 'width'=>'int', 'trimmarker='=>'string', 'encoding='=>'string'], 'mb_stripos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'], 'mb_stristr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'], -'mb_strlen' => ['0|positive-int|false', 'str'=>'string', 'encoding='=>'string'], +'mb_strlen' => ['int|false', 'str'=>'string', 'encoding='=>'string'], 'mb_strpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'encoding='=>'string'], 'mb_strrchr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'], 'mb_strrichr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'], @@ -9585,7 +9585,7 @@ 'RedisCluster::sRandMember' => ['array|string', 'key'=>'string', 'count='=>'int'], 'RedisCluster::sRem' => ['int', 'key'=>'string', 'member1'=>'string', '...other_members='=>'string'], 'RedisCluster::sScan' => ['array', 'key'=>'string', '&iterator'=>'int', 'pattern='=>'null', 'count='=>'int'], -'RedisCluster::strlen' => ['int', 'key'=>'string'], +'RedisCluster::strlen' => ['0|positive-int', 'key'=>'string'], 'RedisCluster::subscribe' => ['mixed', 'channels'=>'array', 'callback'=>'string'], 'RedisCluster::sUnion' => ['array', 'key1'=>'string', '...other_keys='=>'string'], 'RedisCluster::sUnionStore' => ['int', 'dstKey'=>'string', 'key1'=>'string', '...other_keys='=>'string'],