Skip to content

Commit f30db1e

Browse files
committed
Try to make ObjectStorage valid again
1 parent 47245ea commit f30db1e

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

stubs/ObjectStorage.stub

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,62 @@
22
namespace TYPO3\CMS\Extbase\Persistence;
33

44
/**
5-
* @template TKey of object
6-
* @template TEntity of object
5+
* @template TEntity
6+
* @implements \ArrayAccess<string, TEntity>
7+
* @implements \Iterator<string, TEntity>
78
* @phpstan-type ObjectStorageInternal array{obj: TEntity, inf: mixed}
8-
* @implements \ArrayAccess<TKey, TEntity>
9-
* @implements \Iterator<TKey, TEntity>
109
*/
11-
class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonitoringInterface
10+
class ObjectStorage implements \Iterator, \ArrayAccess
1211
{
1312
/**
1413
* @var array<string, ObjectStorageInternal>
1514
*/
16-
protected array $storage;
15+
protected $storage;
1716

1817
/**
19-
* @phpstan-param TEntity $offset
20-
* @param ObjectStorageInternal $information
18+
* @param TEntity|string|null $value
19+
* @param mixed $information
2120
*/
22-
public function offsetSet(mixed $offset, mixed $information): void;
21+
public function offsetSet($value, $information);
2322

2423
/**
25-
* @param TEntity|int $value
24+
* @param TEntity|int|string $value
2625
* @return bool
2726
*/
28-
public function offsetExists(mixed $value);
27+
public function offsetExists($value);
2928

3029
/**
31-
* @param TEntity|int $value
30+
* @param TEntity|int|string $value
3231
*/
33-
public function offsetUnset(mixed $value): void;
32+
public function offsetUnset($value);
3433

3534
/**
36-
* @param TEntity|int $value
37-
* @return ($value is int ? TEntity|null : ObjectStorageInternal)
35+
* @param TEntity|int|string $value
36+
* @return ($value is int ? TEntity|null : mixed)
3837
*/
39-
public function offsetGet(mixed $value);
38+
public function offsetGet($value);
39+
40+
/**
41+
* This is different from the SplObjectStorage as the key in this implementation is the object hash (string).
42+
* @phpstan-ignore-next-line See https://forge.typo3.org/issues/98146
43+
* @return string
44+
*/
45+
// @phpstan-ignore-next-line See https://forge.typo3.org/issues/98146
46+
public function key();
47+
48+
/**
49+
* @return list<TEntity>
50+
*/
51+
public function toArray();
52+
53+
/**
54+
* @return list<TEntity>
55+
*/
56+
public function getArray();
57+
58+
/**
59+
* @param TEntity $object
60+
* @return bool
61+
*/
62+
public function isRelationDirty($object);
4063
}

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<string, MyModel> $objectStorage */
19+
/** @var ObjectStorage<MyModel> $objectStorage */
2020
$objectStorage = new ObjectStorage();
2121
$objectStorage->attach($myModel);
2222

23-
assertType('TYPO3\CMS\Extbase\Persistence\ObjectStorage<string, ' . self::class . '>', $objectStorage);
23+
assertType('TYPO3\CMS\Extbase\Persistence\ObjectStorage<' . 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('array{obj: ObjectStorage\My\Test\Extension\Domain\Model\MyModel, inf: mixed}', $objectStorage->offsetGet($myModel));
39+
assertType('mixed', $objectStorage->offsetGet($myModel));
4040
}
4141

4242
}

0 commit comments

Comments
 (0)