Skip to content

Commit

Permalink
Fix overriding Memcache::get() and MemcachePool::get()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 20, 2021
1 parent fc7d7b4 commit c5f9d24
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/SignatureMap/SignatureMapParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], []);
}

}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Methods/data/memcache-pool-get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace MemcachePoolGet;

class CacheShim extends \MemcachePool
{

public function get($arg, &$flags = null, &$cas = null)
{
return false;
}

}

0 comments on commit c5f9d24

Please sign in to comment.