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
48 changes: 48 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-11507.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types = 1);

use function PHPStan\dumpType;

/**
* @template TValue
*/
class Collection
{
/**
* @param array<int, TValue> $items
*/
public function __construct(
public array $items,
) {}

/**
* Run a map over each of the items.
*
* @template TMapValue
*
* @param callable(TValue, int=): TMapValue $callback
* @return Collection<TMapValue>
*/
public function map(callable $callback)
{
$keys = array_keys($this->items);

$items = array_map($callback, $this->items);

$result = array_combine($keys, $items);

return new self($result);
}
}

/**
* @param Collection<non-empty-array<string>> $collection
* @return Collection<non-empty-array<string>>
*/
function foo(Collection $collection)
{
return $collection->map(function (array $item) {
$item['foo'] = '100';

return $item;
});
}
Loading