Skip to content
Merged
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
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1321,4 +1321,9 @@ public function testBug9669(): void
$this->analyse([__DIR__ . '/data/bug-9669.php'], []);
}

public function testBug10924(): void
{
$this->analyse([__DIR__ . '/data/bug-10924.php'], []);
}

}
110 changes: 110 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-10924.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);

namespace Bug10924;

use function array_key_exists;
use function spl_object_id;

/**
* @phpstan-template T of object
* @phpstan-implements \IteratorAggregate<int, T>
*/
final class ObjectSet implements \IteratorAggregate
{
/**
* @var object[]
* @phpstan-var array<int, T>
*/
private array $objects = [];

/**
* @phpstan-param T ...$objects
*/
public function __construct(object ...$objects)
{
foreach ($objects as $object) {
$this->objects[spl_object_id($object)] = $object;
}
}

/** @phpstan-param T ...$objects */
public function add(object ...$objects): void
{
foreach ($objects as $object) {
$this->objects[spl_object_id($object)] = $object;
}
}

/** @phpstan-param T ...$objects */
public function remove(object ...$objects): void
{
foreach ($objects as $object) {
unset($this->objects[spl_object_id($object)]);
}
}

public function clear(): void
{
$this->objects = [];
}

public function contains(object $object): bool
{
return array_key_exists(spl_object_id($object), $this->objects);
}

/** @phpstan-return \ArrayIterator<int, T> */
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->objects);
}

/**
* @return object[]
* @phpstan-return array<int, T>
*/
public function toArray(): array
{
return $this->objects;
}
}

/**
* @phpstan-type CollectPromise object
*/
class TimingsHandler
{
/** @phpstan-var ObjectSet<\Closure(bool $enable) : void> */
private static ?ObjectSet $toggleCallbacks = null;
/** @phpstan-var ObjectSet<\Closure() : void> */
private static ?ObjectSet $resetCallbacks = null;
/** @phpstan-var ObjectSet<\Closure() : list<CollectPromise>> */
private static ?ObjectSet $collectCallbacks = null;

/**
* @phpstan-return ObjectSet<\Closure(bool $enable) : void>
*/
public static function getToggleCallbacks(): ObjectSet
{
return self::$toggleCallbacks ??= new ObjectSet();
}

/**
* @phpstan-return ObjectSet<\Closure() : void>
*/
public static function getResetCallbacks(): ObjectSet
{
return self::$resetCallbacks ??= new ObjectSet();
}

/**
* @phpstan-return ObjectSet<\Closure() : list<CollectPromise>>
*/
public static function getCollectCallbacks(): ObjectSet
{
return self::$collectCallbacks ??= new ObjectSet();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1050,4 +1050,9 @@ public function testBug4525(): void
$this->analyse([__DIR__ . '/data/bug-4525.php'], []);
}

public function testBug10924(): void
{
$this->analyse([__DIR__ . '/../Methods/data/bug-10924.php'], []);
}

}
Loading