Skip to content

Commit 6f2d1f7

Browse files
committed
Fix ObjectStorage and QueryResultItnerface template in stub
We have to use `TEntity of object` instead of `TEntity`.
1 parent 8a361cf commit 6f2d1f7

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

phpstan-baseline.neon

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors: []

stubs/ObjectStorage.stub

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace TYPO3\CMS\Extbase\Persistence;
33

44
/**
5-
* @template TEntity
5+
* @template TEntity of object
66
* @implements \ArrayAccess<string, TEntity>
77
* @implements \Iterator<string, TEntity>
88
* @phpstan-type ObjectStorageInternal array{obj: TEntity, inf: mixed}
@@ -33,6 +33,8 @@ class ObjectStorage implements \Iterator, \ArrayAccess
3333

3434
/**
3535
* @param TEntity|int|string $value
36+
* Attention: Return type is not compatible with ArrayAccess interface! This
37+
* is a bug in TYPO3.
3638
* @return ($value is int ? TEntity|null : mixed)
3739
*/
3840
public function offsetGet($value);

stubs/QueryResultInterface.stub

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace TYPO3\CMS\Extbase\Persistence;
33

44
/**
5-
* @template TKey
5+
* @template TKey of int
66
* @template TValue of object
77
* @extends \Iterator<TKey, TValue>
88
* @extends \ArrayAccess<TKey, TValue>

tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public function showAction(): void
135135
'list<SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension\FrontendUserGroup>',
136136
$myObjects
137137
);
138+
139+
$key = $queryResult->key();
140+
assertType(
141+
'int',
142+
$key
143+
);
138144
}
139145

140146
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function foo(): void
2929
}
3030

3131
assertType(self::class . '|null', $objectStorage->offsetGet(0));
32+
assertType(self::class . '|null', $objectStorage->current());
3233

3334
// We ignore errors in the next line as this will produce an
3435
// "Offset 0 does not exist on TYPO3\CMS\Extbase\Persistence\ObjectStorage<ObjectStorage\My\Test\Extension\Domain\Model\MyModel>

0 commit comments

Comments
 (0)