Skip to content

Commit 3d36763

Browse files
committed
Merge branch 2.1.x into 2.2.x
2 parents d05e954 + 72a52e0 commit 3d36763

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,4 +1321,9 @@ public function testBug9669(): void
13211321
$this->analyse([__DIR__ . '/data/bug-9669.php'], []);
13221322
}
13231323

1324+
public function testBug10924(): void
1325+
{
1326+
$this->analyse([__DIR__ . '/data/bug-10924.php'], []);
1327+
}
1328+
13241329
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bug10924;
6+
7+
use function array_key_exists;
8+
use function spl_object_id;
9+
10+
/**
11+
* @phpstan-template T of object
12+
* @phpstan-implements \IteratorAggregate<int, T>
13+
*/
14+
final class ObjectSet implements \IteratorAggregate
15+
{
16+
/**
17+
* @var object[]
18+
* @phpstan-var array<int, T>
19+
*/
20+
private array $objects = [];
21+
22+
/**
23+
* @phpstan-param T ...$objects
24+
*/
25+
public function __construct(object ...$objects)
26+
{
27+
foreach ($objects as $object) {
28+
$this->objects[spl_object_id($object)] = $object;
29+
}
30+
}
31+
32+
/** @phpstan-param T ...$objects */
33+
public function add(object ...$objects): void
34+
{
35+
foreach ($objects as $object) {
36+
$this->objects[spl_object_id($object)] = $object;
37+
}
38+
}
39+
40+
/** @phpstan-param T ...$objects */
41+
public function remove(object ...$objects): void
42+
{
43+
foreach ($objects as $object) {
44+
unset($this->objects[spl_object_id($object)]);
45+
}
46+
}
47+
48+
public function clear(): void
49+
{
50+
$this->objects = [];
51+
}
52+
53+
public function contains(object $object): bool
54+
{
55+
return array_key_exists(spl_object_id($object), $this->objects);
56+
}
57+
58+
/** @phpstan-return \ArrayIterator<int, T> */
59+
public function getIterator(): \ArrayIterator
60+
{
61+
return new \ArrayIterator($this->objects);
62+
}
63+
64+
/**
65+
* @return object[]
66+
* @phpstan-return array<int, T>
67+
*/
68+
public function toArray(): array
69+
{
70+
return $this->objects;
71+
}
72+
}
73+
74+
/**
75+
* @phpstan-type CollectPromise object
76+
*/
77+
class TimingsHandler
78+
{
79+
/** @phpstan-var ObjectSet<\Closure(bool $enable) : void> */
80+
private static ?ObjectSet $toggleCallbacks = null;
81+
/** @phpstan-var ObjectSet<\Closure() : void> */
82+
private static ?ObjectSet $resetCallbacks = null;
83+
/** @phpstan-var ObjectSet<\Closure() : list<CollectPromise>> */
84+
private static ?ObjectSet $collectCallbacks = null;
85+
86+
/**
87+
* @phpstan-return ObjectSet<\Closure(bool $enable) : void>
88+
*/
89+
public static function getToggleCallbacks(): ObjectSet
90+
{
91+
return self::$toggleCallbacks ??= new ObjectSet();
92+
}
93+
94+
/**
95+
* @phpstan-return ObjectSet<\Closure() : void>
96+
*/
97+
public static function getResetCallbacks(): ObjectSet
98+
{
99+
return self::$resetCallbacks ??= new ObjectSet();
100+
}
101+
102+
/**
103+
* @phpstan-return ObjectSet<\Closure() : list<CollectPromise>>
104+
*/
105+
public static function getCollectCallbacks(): ObjectSet
106+
{
107+
return self::$collectCallbacks ??= new ObjectSet();
108+
}
109+
110+
}

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,4 +1050,9 @@ public function testBug4525(): void
10501050
$this->analyse([__DIR__ . '/data/bug-4525.php'], []);
10511051
}
10521052

1053+
public function testBug10924(): void
1054+
{
1055+
$this->analyse([__DIR__ . '/../Methods/data/bug-10924.php'], []);
1056+
}
1057+
10531058
}

0 commit comments

Comments
 (0)