Skip to content

Commit 1b27922

Browse files
committed
Add offsetGet to stub again
1 parent 8c8c727 commit 1b27922

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

phpstan.neon

-15
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,10 @@ parameters:
1818
- '*tests/*/Source/*'
1919
- '*tests/*/data/*'
2020
ignoreErrors:
21-
-
22-
message: '#^Class TYPO3\\CMS\\Core\\Context\\[a-zA-Z]* not found\.#'
23-
path: src/Type/ContextDynamicReturnTypeExtension.php
2421
-
2522
message: "#^Calling PHPStan\\\\Reflection\\\\InitializerExprTypeResolver\\:\\:getClassConstFetchType\\(\\) is not covered by backward compatibility promise\\. The method might change in a minor PHPStan version\\.$#"
2623
count: 1
2724
path: src/Rule/ValidatorResolverOptionsRule.php
28-
-
29-
message: "#^Method SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroupCustomFindAllWithoutModelTypeRepository\\:\\:findAll\\(\\) return type with generic interface TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface does not specify its types\\: ModelType$#"
30-
count: 1
31-
path: tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php
32-
-
33-
message: "#^PHPDoc tag @var for variable \\$queryResult contains generic class TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Generic\\\\QueryResult but does not specify its types\\: ModelType$#"
34-
count: 2
35-
path: tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php
36-
-
37-
message: "#^Return type \\(TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface\\) of method SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroupCustomFindAllWithoutModelTypeRepository\\:\\:findAll\\(\\) should be covariant with return type \\(array\\<int, SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroup\\>\\|TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryResultInterface\\<SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroup\\>\\) of method TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Repository\\<SaschaEgerer\\\\PhpstanTypo3\\\\Tests\\\\Unit\\\\Type\\\\QueryResultToArrayDynamicReturnTypeExtension\\\\FrontendUserGroup\\>\\:\\:findAll\\(\\)$#"
38-
count: 1
39-
path: tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php
4025
-
4126
message: '#^Although PHPStan\\Reflection\\Php\\PhpPropertyReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#'
4227
identifier: phpstanApi.instanceofAssumption

stubs/ObjectStorage.stub

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class ObjectStorage implements \Iterator, \ArrayAccess
2020
*/
2121
public function offsetSet($value, $information);
2222

23+
/**
24+
* @param TEntity|string|int $value
25+
* @phpstan-return TEntity|null
26+
*/
27+
public function offsetGet(mixed $value);
28+
2329
/**
2430
* @param TEntity|int|string $value
2531
* @return bool
@@ -33,11 +39,9 @@ class ObjectStorage implements \Iterator, \ArrayAccess
3339

3440
/**
3541
* This is different from the SplObjectStorage as the key in this implementation is the object hash (string).
36-
* @phpstan-ignore-next-line See https://forge.typo3.org/issues/98146
3742
* @return string
3843
*/
39-
// @phpstan-ignore-next-line See https://forge.typo3.org/issues/98146
40-
public function key();
44+
public function key(): string;
4145

4246
/**
4347
* @return list<TEntity>

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@ public function checkArrayAccess(): void
4141
assertType(self::class . '|null', $this->testStorage->offsetGet(0));
4242
assertType(self::class . '|null', $this->testStorage->offsetGet('0'));
4343
assertType(self::class . '|null', $this->testStorage->current());
44-
45-
// We ignore errors in the next line as this will produce an
46-
// "Offset 0 does not exist on TYPO3\CMS\Extbase\Persistence\ObjectStorage<ObjectStorage\My\Test\Extension\Domain\Model\MyModel>
47-
// due to the weird implementation of ArrayAccess in ObjectStorage::offsetGet()
48-
// @phpstan-ignore-next-line
4944
assertType(self::class . '|null', $this->testStorage[0]);
5045

5146
$myModel = new self();
5247

48+
assertType('mixed', $this->testStorage->offsetGet($this->testStorage->current()));
5349
assertType('mixed', $this->testStorage->offsetGet($myModel));
5450
}
5551

0 commit comments

Comments
 (0)