diff --git a/src/PhpDoc/StubPhpDocProvider.php b/src/PhpDoc/StubPhpDocProvider.php index 78247f4145..c00f41f735 100644 --- a/src/PhpDoc/StubPhpDocProvider.php +++ b/src/PhpDoc/StubPhpDocProvider.php @@ -29,7 +29,7 @@ class StubPhpDocProvider /** @var array> */ private $propertyMap = []; - /** @var array> */ + /** @var array> */ private $methodMap = []; /** @var array */ @@ -162,7 +162,7 @@ public function findMethodPhpDoc(string $className, string $methodName, array $p $parameterNameMapping[$methodParameterNames[$i]] = $parameterName; } - return $this->methodMap[$className][$methodName] = $resolvedPhpDoc->changeParameterNamesByMapping($parameterNameMapping); + return $resolvedPhpDoc->changeParameterNamesByMapping($parameterNameMapping); } return null; diff --git a/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php b/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php index 978a8ca943..088c602cb2 100644 --- a/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php @@ -190,4 +190,11 @@ public function testRuleWithStaticMethods(): void ]); } + public function testBug2950(): void + { + $this->reportMaybes = true; + $this->reportStatic = true; + $this->analyse([__DIR__ . '/data/bug-2950.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-2950.php b/tests/PHPStan/Rules/Methods/data/bug-2950.php new file mode 100644 index 0000000000..8e5c980034 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-2950.php @@ -0,0 +1,119 @@ + */ + private static $fullList = null; + + public static function isRegistered(int $id): bool + { + $b = self::$fullList[$id << 4]; + return $b !== null; + } +} + +class Attribute +{ + + public function getId(): int + { + return 0; + } + + public function isSyncable(): bool + { + return false; + } + + public function isDesynchronized(): bool + { + return false; + } + + public function getValue(): float + { + return 0.0; + } + + public function setValue(float $f) : self + { + return $this; + } +} + + + +/** + * @phpstan-implements \ArrayAccess + */ +class AttributeMap implements \ArrayAccess +{ + + /** @var Attribute[] */ + private $attributes = []; + + public function addAttribute(Attribute $attribute): void + { + $this->attributes[$attribute->getId()] = $attribute; + } + + public function getAttribute(int $id): ?Attribute + { + return $this->attributes[$id] ?? null; + } + + /** + * @return Attribute[] + */ + public function getAll(): array + { + return $this->attributes; + } + + /** + * @return Attribute[] + */ + public function needSend(): array + { + return array_filter($this->attributes, function(Attribute $attribute){ + return $attribute->isSyncable() and $attribute->isDesynchronized(); + }); + } + + /** + * @param int $offset + */ + public function offsetExists($offset): bool + { + return isset($this->attributes[$offset]); + } + + /** + * @param int $offset + */ + public function offsetGet($offset): float + { + return $this->attributes[$offset]->getValue(); + } + + /** + * @param int $offset + * @param float $value + */ + public function offsetSet($offset, $value): void + { + $this->attributes[$offset]->setValue($value); + } + + /** + * @param int $offset + */ + public function offsetUnset($offset): void + { + throw new \RuntimeException("Could not unset an attribute from an attribute map"); + } + +}