From 3c602241a7d99cdca9b459ee57058215c97b30ce Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 15 May 2024 22:57:09 +0200 Subject: [PATCH] [CLEANUP] Use specific PHPStan error code in the annotations (#602) Also harden some array accesses in the tests. Fixes #586 --- .../Repository/FrontendUserGroupRepositoryTest.php | 2 +- Tests/Unit/Domain/Model/FrontendUserGroupTest.php | 11 ++++++----- Tests/Unit/Domain/Model/FrontendUserTest.php | 10 ++++++---- .../Repository/FrontendUserGroupRepositoryTest.php | 2 +- .../Domain/Repository/FrontendUserRepositoryTest.php | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Tests/Functional/Domain/Repository/FrontendUserGroupRepositoryTest.php b/Tests/Functional/Domain/Repository/FrontendUserGroupRepositoryTest.php index 0c7f85d..cdd1e81 100644 --- a/Tests/Functional/Domain/Repository/FrontendUserGroupRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/FrontendUserGroupRepositoryTest.php @@ -101,7 +101,7 @@ public function findByUidsSilentlyIgnoresNonStringUids(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/UserGroupWithAllScalarData.csv'); - // @phpstan-ignore-next-line We are explicitly testing with a contract-violating value. + // @phpstan-ignore argument.type (We are explicitly testing with a contract-violating value.) $models = $this->subject->findByUids([1, '\'"--ab']); self::assertCount(1, $models); diff --git a/Tests/Unit/Domain/Model/FrontendUserGroupTest.php b/Tests/Unit/Domain/Model/FrontendUserGroupTest.php index 858654f..be6befc 100644 --- a/Tests/Unit/Domain/Model/FrontendUserGroupTest.php +++ b/Tests/Unit/Domain/Model/FrontendUserGroupTest.php @@ -29,8 +29,8 @@ protected function setUp(): void protected function tearDown(): void { - // @phpstan-ignore-next-line We know that the necessary array keys exist. - unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][FrontendUserGroup::class]); + // @phpstan-ignore offsetAccess.nonOffsetAccessible, offsetAccess.nonOffsetAccessible + unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']); MakeInstanceCacheFlusher::flushMakeInstanceCache(); parent::tearDown(); } @@ -48,9 +48,10 @@ public function isAbstractEntity(): void */ public function canBeSubclassed(): void { - // @phpstan-ignore-next-line We know that the necessary array keys exist. - $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][FrontendUserGroup::class] - = ['className' => XclassFrontendUserGroup::class]; + // @phpstan-ignore offsetAccess.nonOffsetAccessible, offsetAccess.nonOffsetAccessible + $xclassConfiguration = &$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']; + self::assertIsArray($xclassConfiguration); + $xclassConfiguration[FrontendUserGroup::class] = ['className' => XclassFrontendUserGroup::class]; $instance = GeneralUtility::makeInstance(FrontendUserGroup::class); diff --git a/Tests/Unit/Domain/Model/FrontendUserTest.php b/Tests/Unit/Domain/Model/FrontendUserTest.php index 6d14f3b..d68cc5f 100644 --- a/Tests/Unit/Domain/Model/FrontendUserTest.php +++ b/Tests/Unit/Domain/Model/FrontendUserTest.php @@ -31,8 +31,8 @@ protected function setUp(): void protected function tearDown(): void { - // @phpstan-ignore-next-line We know that the necessary array keys exist. - unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][FrontendUser::class]); + // @phpstan-ignore offsetAccess.nonOffsetAccessible, offsetAccess.nonOffsetAccessible + unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']); MakeInstanceCacheFlusher::flushMakeInstanceCache(); parent::tearDown(); } @@ -50,8 +50,10 @@ public function isAbstractEntity(): void */ public function canBeSubclassed(): void { - // @phpstan-ignore-next-line We know that the necessary array keys exist. - $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][FrontendUser::class] = ['className' => XclassFrontendUser::class]; + // @phpstan-ignore offsetAccess.nonOffsetAccessible, offsetAccess.nonOffsetAccessible + $xclassConfiguration = &$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']; + self::assertIsArray($xclassConfiguration); + $xclassConfiguration[FrontendUser::class] = ['className' => XclassFrontendUser::class]; $instance = GeneralUtility::makeInstance(FrontendUser::class); diff --git a/Tests/Unit/Domain/Repository/FrontendUserGroupRepositoryTest.php b/Tests/Unit/Domain/Repository/FrontendUserGroupRepositoryTest.php index cb51e4f..fcd22ca 100644 --- a/Tests/Unit/Domain/Repository/FrontendUserGroupRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/FrontendUserGroupRepositoryTest.php @@ -24,7 +24,7 @@ protected function setUp(): void if (\interface_exists(ObjectManagerInterface::class)) { $objectManagerStub = $this->createStub(ObjectManagerInterface::class); - // @phpstan-ignore-next-line This line is 11LTS-specific, but we're running PHPStan on TYPO3 12. + // @phpstan-ignore arguments.count (This line is 11LTS-specific, but we're running PHPStan on TYPO3 12.) $this->subject = new FrontendUserGroupRepository($objectManagerStub); } else { $this->subject = new FrontendUserGroupRepository(); diff --git a/Tests/Unit/Domain/Repository/FrontendUserRepositoryTest.php b/Tests/Unit/Domain/Repository/FrontendUserRepositoryTest.php index 1df501d..c64ad59 100644 --- a/Tests/Unit/Domain/Repository/FrontendUserRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/FrontendUserRepositoryTest.php @@ -24,7 +24,7 @@ protected function setUp(): void if (\interface_exists(ObjectManagerInterface::class)) { $objectManagerStub = $this->createStub(ObjectManagerInterface::class); - // @phpstan-ignore-next-line This line is 11LTS-specific, but we're running PHPStan on TYPO3 12. + // @phpstan-ignore arguments.count (This line is 11LTS-specific, but we're running PHPStan on TYPO3 12.) $this->subject = new FrontendUserRepository($objectManagerStub); } else { $this->subject = new FrontendUserRepository();