From c5f9d2400ee430a4850a87186a751d1e1d9fc9be Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 20 Jul 2021 13:28:04 +0200 Subject: [PATCH] Fix overriding Memcache::get() and MemcachePool::get() --- resources/functionMap.php | 4 ++-- src/Reflection/SignatureMap/SignatureMapParser.php | 2 +- .../Rules/Methods/MethodSignatureRuleTest.php | 11 +++++++++++ .../Rules/Methods/data/memcache-pool-get.php | 13 +++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/PHPStan/Rules/Methods/data/memcache-pool-get.php diff --git a/resources/functionMap.php b/resources/functionMap.php index 5db68060ee..59374884c9 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -6412,7 +6412,7 @@ 'Memcache::decrement' => ['int', 'key'=>'string', 'value='=>'int'], 'Memcache::delete' => ['bool', 'key'=>'string', 'timeout='=>'int'], 'Memcache::flush' => ['bool'], -'Memcache::get' => ['string|array|false', 'key'=>'string', 'flags='=>'array', 'keys='=>'array'], +'Memcache::get' => ['string|array|false', 'key'=>'string', '&flags='=>'array', '&keys='=>'array'], 'Memcache::getExtendedStats' => ['array', 'type='=>'string', 'slabid='=>'int', 'limit='=>'int'], 'Memcache::getServerStatus' => ['int', 'host'=>'string', 'port='=>'int'], 'Memcache::getStats' => ['array', 'type='=>'string', 'slabid='=>'int', 'limit='=>'int'], @@ -6479,7 +6479,7 @@ 'MemcachePool::decrement' => ['int', 'key'=>'string', 'value='=>'int'], 'MemcachePool::delete' => ['bool', 'key'=>'string', 'timeout='=>'int'], 'MemcachePool::flush' => ['bool'], -'MemcachePool::get' => ['string|array|false', 'key'=>'string', 'flags='=>'array', 'keys='=>'array'], +'MemcachePool::get' => ['string|array|false', 'key'=>'string', '&flags='=>'array', '&keys='=>'array'], 'MemcachePool::getExtendedStats' => ['array', 'type='=>'string', 'slabid='=>'int', 'limit='=>'int'], 'MemcachePool::getServerStatus' => ['int', 'host'=>'string', 'port='=>'int'], 'MemcachePool::getStats' => ['array', 'type='=>'string', 'slabid='=>'int', 'limit='=>'int'], diff --git a/src/Reflection/SignatureMap/SignatureMapParser.php b/src/Reflection/SignatureMap/SignatureMapParser.php index 2a4e203d85..166025c41c 100644 --- a/src/Reflection/SignatureMap/SignatureMapParser.php +++ b/src/Reflection/SignatureMap/SignatureMapParser.php @@ -97,7 +97,7 @@ private function getParameterInfoFromName(string $parameterNameString): array } if (strpos($reference, '&rw') === 0) { $passedByReference = PassedByReference::createReadsArgument(); - } elseif (strpos($reference, '&w') === 0) { + } elseif (strpos($reference, '&w') === 0 || strpos($reference, '&') === 0) { $passedByReference = PassedByReference::createCreatesNewVariable(); } else { $passedByReference = PassedByReference::createNo(); diff --git a/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php b/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php index 080a6e4a3e..536dff3540 100644 --- a/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php @@ -351,4 +351,15 @@ public function testBug4854(): void $this->analyse([__DIR__ . '/data/bug-4854.php'], []); } + public function testMemcachePoolGet(): void + { + if (!self::$useStaticReflectionProvider) { + $this->markTestSkipped('Test requires static reflection.'); + } + + $this->reportMaybes = true; + $this->reportStatic = true; + $this->analyse([__DIR__ . '/data/memcache-pool-get.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/memcache-pool-get.php b/tests/PHPStan/Rules/Methods/data/memcache-pool-get.php new file mode 100644 index 0000000000..711560b787 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/memcache-pool-get.php @@ -0,0 +1,13 @@ +