From 278e88b642a741826e758f3c21ae41a85333636c Mon Sep 17 00:00:00 2001 From: HawkForge <75696486+HawkForge@users.noreply.github.com> Date: Thu, 15 Oct 2026 16:46:18 +0600 Subject: [PATCH] Add regression test for #11507 Refs https://github.com/phpstan/phpstan/issues/11507 --- .../Rules/Functions/ReturnTypeRuleTest.php | 8 +++ .../Rules/Functions/data/bug-11507.php | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/PHPStan/Rules/Functions/data/bug-11507.php 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; + }); +}