Skip to content

Commit

Permalink
Try to make ObjectStorage valid again
Browse files Browse the repository at this point in the history
  • Loading branch information
sascha-egerer committed Jan 16, 2025
1 parent 47245ea commit f30db1e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
55 changes: 39 additions & 16 deletions stubs/ObjectStorage.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,62 @@
namespace TYPO3\CMS\Extbase\Persistence;

/**
* @template TKey of object
* @template TEntity of object
* @template TEntity
* @implements \ArrayAccess<string, TEntity>
* @implements \Iterator<string, TEntity>
* @phpstan-type ObjectStorageInternal array{obj: TEntity, inf: mixed}
* @implements \ArrayAccess<TKey, TEntity>
* @implements \Iterator<TKey, TEntity>
*/
class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonitoringInterface
class ObjectStorage implements \Iterator, \ArrayAccess
{
/**
* @var array<string, ObjectStorageInternal>
*/
protected array $storage;
protected $storage;

/**
* @phpstan-param TEntity $offset
* @param ObjectStorageInternal $information
* @param TEntity|string|null $value
* @param mixed $information
*/
public function offsetSet(mixed $offset, mixed $information): void;
public function offsetSet($value, $information);

/**
* @param TEntity|int $value
* @param TEntity|int|string $value
* @return bool
*/
public function offsetExists(mixed $value);
public function offsetExists($value);

/**
* @param TEntity|int $value
* @param TEntity|int|string $value
*/
public function offsetUnset(mixed $value): void;
public function offsetUnset($value);

/**
* @param TEntity|int $value
* @return ($value is int ? TEntity|null : ObjectStorageInternal)
* @param TEntity|int|string $value
* @return ($value is int ? TEntity|null : mixed)
*/
public function offsetGet(mixed $value);
public function offsetGet($value);

/**
* This is different from the SplObjectStorage as the key in this implementation is the object hash (string).
* @phpstan-ignore-next-line See https://forge.typo3.org/issues/98146
* @return string
*/
// @phpstan-ignore-next-line See https://forge.typo3.org/issues/98146
public function key();

/**
* @return list<TEntity>
*/
public function toArray();

/**
* @return list<TEntity>
*/
public function getArray();

/**
* @param TEntity $object
* @return bool
*/
public function isRelationDirty($object);
}
6 changes: 3 additions & 3 deletions tests/Unit/Type/data/object-storage-stub-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class MyModel extends AbstractEntity
public function foo(): void
{
$myModel = new self();
/** @var ObjectStorage<string, MyModel> $objectStorage */
/** @var ObjectStorage<MyModel> $objectStorage */
$objectStorage = new ObjectStorage();
$objectStorage->attach($myModel);

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

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

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

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

}

0 comments on commit f30db1e

Please sign in to comment.