diff --git a/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php index 3a03a0fd36f..daccbe3882c 100644 --- a/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php @@ -534,6 +534,14 @@ public function testBug8031(): void $this->analyse([__DIR__ . '/data/bug-8031.php'], []); } + #[RequiresPhp('>= 8.0.0')] + public function testBug11507(): void + { + $this->checkNullables = true; + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-11507.php'], []); + } + public function testBug15245(): void { $this->checkNullables = true; diff --git a/tests/PHPStan/Rules/Functions/data/bug-11507.php b/tests/PHPStan/Rules/Functions/data/bug-11507.php new file mode 100644 index 00000000000..ceb791a70b9 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-11507.php @@ -0,0 +1,52 @@ += 8.0 + +declare(strict_types = 1); + +namespace Bug11507; + +/** + * @template TKey of array-key + * + * @template TValue + */ +class Collection +{ + /** + * @param array $items + */ + public function __construct( + public array $items, + ) {} + + /** + * Run a map over each of the items. + * + * @template TMapValue + * + * @param callable(TValue, TKey): TMapValue $callback + * @return static + */ + public function map(callable $callback) + { + $keys = array_keys($this->items); + + $items = array_map($callback, $this->items, $keys); + + $result = array_combine($keys, $items); + + return new self($result); + } +} + +/** + * @param Collection> $collection + * @return Collection> + */ +function foo(Collection $collection) +{ + return $collection->map(function (array $item) { + $item['foo'] = '100'; + + return $item; + }); +}