Skip to content

Commit 48fb114

Browse files
committed
Solve some issues with ObjectStorage.stub
1 parent 83a9b80 commit 48fb114

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace TYPO3\CMS\Extbase\Persistence;
3+
4+
interface ObjectMonitoringInterface {}

stubs/ObjectStorage.stub

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
namespace TYPO3\CMS\Extbase\Persistence;
33

44
/**
5+
* @template TKey of object
56
* @template TEntity of object
6-
* @implements \ArrayAccess<string, TEntity>
7-
* @implements \Iterator<string, TEntity>
87
* @phpstan-type ObjectStorageInternal array{obj: TEntity, inf: mixed}
8+
* @implements \ArrayAccess<TKey, TEntity>
9+
* @implements \Iterator<TKey, TEntity>
910
*/
10-
class ObjectStorage implements \Iterator, \ArrayAccess
11+
class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonitoringInterface
1112
{
1213
/**
1314
* @var array<string, ObjectStorageInternal>
1415
*/
1516
protected array $storage;
1617

1718
/**
18-
* @param TEntity $object
19-
* @param mixed $information
19+
* @phpstan-param TEntity $offset
20+
* @param ObjectStorageInternal $information
2021
*/
21-
public function offsetSet(mixed $object, mixed $information);
22+
public function offsetSet(mixed $offset, mixed $information): void;
2223

2324
/**
2425
* @param TEntity|int $value
@@ -29,11 +30,11 @@ class ObjectStorage implements \Iterator, \ArrayAccess
2930
/**
3031
* @param TEntity|int $value
3132
*/
32-
public function offsetUnset(mixed $value);
33+
public function offsetUnset(mixed $value): void;
3334

3435
/**
3536
* @param TEntity|int $value
36-
* @return ($value is int ? TEntity|null : mixed)
37+
* @return ($value is int ? TEntity|null : ObjectStorageInternal)
3738
*/
3839
public function offsetGet(mixed $value);
3940
}

tests/Unit/Type/data/object-storage-stub-files.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class MyModel extends AbstractEntity
1616
public function foo(): void
1717
{
1818
$myModel = new self();
19-
/** @var ObjectStorage<MyModel> $objectStorage */
19+
/** @var ObjectStorage<string, MyModel> $objectStorage */
2020
$objectStorage = new ObjectStorage();
2121
$objectStorage->attach($myModel);
2222

23-
assertType('TYPO3\CMS\Extbase\Persistence\ObjectStorage<' . self::class . '>', $objectStorage);
23+
assertType('TYPO3\CMS\Extbase\Persistence\ObjectStorage<string, ' . self::class . '>', $objectStorage);
2424

2525
foreach ($objectStorage as $key => $value) {
2626

@@ -36,7 +36,7 @@ public function foo(): void
3636
// @phpstan-ignore-next-line
3737
assertType(self::class . '|null', $objectStorage[0]);
3838

39-
assertType('mixed', $objectStorage->offsetGet($myModel));
39+
assertType('array{obj: ObjectStorage\My\Test\Extension\Domain\Model\MyModel, inf: mixed}', $objectStorage->offsetGet($myModel));
4040
}
4141

4242
}

0 commit comments

Comments
 (0)