Skip to content

Commit

Permalink
Solve some issues with ObjectStorage.stub
Browse files Browse the repository at this point in the history
  • Loading branch information
sascha-egerer committed Jan 16, 2025
1 parent 83a9b80 commit 48fb114
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions stubs/ObjectMonitoringInterface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
namespace TYPO3\CMS\Extbase\Persistence;

interface ObjectMonitoringInterface {}
17 changes: 9 additions & 8 deletions stubs/ObjectStorage.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
namespace TYPO3\CMS\Extbase\Persistence;

/**
* @template TKey of object
* @template TEntity of object
* @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 \Iterator, \ArrayAccess
class ObjectStorage implements \Countable, \Iterator, \ArrayAccess, ObjectMonitoringInterface

Check failure on line 11 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3)

Class TYPO3\CMS\Extbase\Persistence\ObjectStorage implements unknown interface TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface.

Check failure on line 11 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3, --prefer-lowest)

Class TYPO3\CMS\Extbase\Persistence\ObjectStorage implements unknown interface TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface.

Check failure on line 11 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4)

Class TYPO3\CMS\Extbase\Persistence\ObjectStorage implements unknown interface TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface.

Check failure on line 11 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4, --prefer-lowest)

Class TYPO3\CMS\Extbase\Persistence\ObjectStorage implements unknown interface TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface.
{
/**
* @var array<string, ObjectStorageInternal>
*/
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;

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3)

Parameter #1 $offset (TEntity of object) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be contravariant with parameter $offset (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3)

Parameter #2 $information (array{obj: TEntity of object, inf: mixed}) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be compatible with parameter $value (object) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3, --prefer-lowest)

Parameter #1 $offset (TEntity of object) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be contravariant with parameter $offset (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3, --prefer-lowest)

Parameter #2 $information (array{obj: TEntity of object, inf: mixed}) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be compatible with parameter $value (object) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4)

Parameter #1 $offset (TEntity of object) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be contravariant with parameter $offset (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4)

Parameter #2 $information (array{obj: TEntity of object, inf: mixed}) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be compatible with parameter $value (object) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4, --prefer-lowest)

Parameter #1 $offset (TEntity of object) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be contravariant with parameter $offset (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

Check failure on line 22 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4, --prefer-lowest)

Parameter #2 $information (array{obj: TEntity of object, inf: mixed}) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetSet() should be compatible with parameter $value (object) of method ArrayAccess<TKey of object,TEntity of object>::offsetSet()

/**
* @param TEntity|int $value
Expand All @@ -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);

Check failure on line 39 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3)

Return type (($value is int ? (TEntity of object)|null : array{obj: TEntity of object, inf: mixed})) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetGet() should be covariant with return type (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetGet()

Check failure on line 39 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.3, --prefer-lowest)

Return type (($value is int ? (TEntity of object)|null : array{obj: TEntity of object, inf: mixed})) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetGet() should be covariant with return type (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetGet()

Check failure on line 39 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4)

Return type (($value is int ? (TEntity of object)|null : array{obj: TEntity of object, inf: mixed})) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetGet() should be covariant with return type (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetGet()

Check failure on line 39 in stubs/ObjectStorage.stub

View workflow job for this annotation

GitHub Actions / Tests (^13.4, 8.4, --prefer-lowest)

Return type (($value is int ? (TEntity of object)|null : array{obj: TEntity of object, inf: mixed})) of method TYPO3\CMS\Extbase\Persistence\ObjectStorage::offsetGet() should be covariant with return type (object|null) of method ArrayAccess<TKey of object,TEntity of object>::offsetGet()
}
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<MyModel> $objectStorage */
/** @var ObjectStorage<string, MyModel> $objectStorage */
$objectStorage = new ObjectStorage();
$objectStorage->attach($myModel);

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

}

0 comments on commit 48fb114

Please sign in to comment.