Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 52 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-11507.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug11507;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems this snippet was adopted and does not reflect 1:1 the reported reproducer of phpstan/phpstan#11507 (comment) ?


/**
* @template TKey of array-key
*
* @template TValue
*/
class Collection
{
/**
* @param array<TKey, TValue> $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<TKey, TMapValue>
*/
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<int, non-empty-array<string, string>> $collection
* @return Collection<int, non-empty-array<string, string>>
*/
function foo(Collection $collection)
{
return $collection->map(function (array $item) {
$item['foo'] = '100';

return $item;
});
}
Loading