From 48fb114f32781ef1c7a52e750cf7b4adbd051a9c Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Thu, 16 Jan 2025 23:01:07 +0100 Subject: [PATCH] Solve some issues with ObjectStorage.stub --- stubs/ObjectMonitoringInterface.stub | 4 ++++ stubs/ObjectStorage.stub | 17 +++++++++-------- .../Type/data/object-storage-stub-files.php | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 stubs/ObjectMonitoringInterface.stub diff --git a/stubs/ObjectMonitoringInterface.stub b/stubs/ObjectMonitoringInterface.stub new file mode 100644 index 0000000..a09f5e6 --- /dev/null +++ b/stubs/ObjectMonitoringInterface.stub @@ -0,0 +1,4 @@ + - * @implements \Iterator * @phpstan-type ObjectStorageInternal array{obj: TEntity, inf: mixed} + * @implements \ArrayAccess + * @implements \Iterator */ -class ObjectStorage implements \Iterator, \ArrayAccess +class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonitoringInterface { /** * @var array @@ -15,10 +16,10 @@ class ObjectStorage implements \Iterator, \ArrayAccess protected array $storage; /** - * @param TEntity $object - * @param mixed $information + * @phpstan-param TEntity $offset + * @param ObjectStorageInternal $information */ - public function offsetSet(mixed $object, mixed $information); + public function offsetSet(mixed $offset, mixed $information): void; /** * @param TEntity|int $value @@ -29,11 +30,11 @@ class ObjectStorage implements \Iterator, \ArrayAccess /** * @param TEntity|int $value */ - public function offsetUnset(mixed $value); + public function offsetUnset(mixed $value): void; /** * @param TEntity|int $value - * @return ($value is int ? TEntity|null : mixed) + * @return ($value is int ? TEntity|null : ObjectStorageInternal) */ public function offsetGet(mixed $value); } diff --git a/tests/Unit/Type/data/object-storage-stub-files.php b/tests/Unit/Type/data/object-storage-stub-files.php index 4e8df82..42e0607 100644 --- a/tests/Unit/Type/data/object-storage-stub-files.php +++ b/tests/Unit/Type/data/object-storage-stub-files.php @@ -16,11 +16,11 @@ class MyModel extends AbstractEntity public function foo(): void { $myModel = new self(); - /** @var ObjectStorage $objectStorage */ + /** @var ObjectStorage $objectStorage */ $objectStorage = new ObjectStorage(); $objectStorage->attach($myModel); - assertType('TYPO3\CMS\Extbase\Persistence\ObjectStorage<' . self::class . '>', $objectStorage); + assertType('TYPO3\CMS\Extbase\Persistence\ObjectStorage', $objectStorage); foreach ($objectStorage as $key => $value) { @@ -36,7 +36,7 @@ public function foo(): void // @phpstan-ignore-next-line assertType(self::class . '|null', $objectStorage[0]); - assertType('mixed', $objectStorage->offsetGet($myModel)); + assertType('array{obj: ObjectStorage\My\Test\Extension\Domain\Model\MyModel, inf: mixed}', $objectStorage->offsetGet($myModel)); } }