Skip to content

Commit f76dce7

Browse files
committed
[BUGFIX] Mitigate deprecated extbase ViewInterface
TYPO3 v11.5 started streamlining the view implementation, which included deprecating the extbase `ViewInterface`. Extensions supporting two TYPO3 core version need to take care and the migration path for controllers overriding the `initialzeView` method is stated in the changelog [1]. This change follows the recommended migration path and removes the deprecated interface as method native type declarion for the `$view` argument, avoiding in TYPO3 v12 the exception TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException Class "TYPO3\CMS\Extbase\Mvc\View\ViewInterface" does not exist. Reflection failed. while still making required adjustments. We need to add one error to the TYPO3 v12 phpstan baseline as the error is not reported in TYPO3 v11 and using the `phpstan-ignore` annotation does not work. Dispatching a callable is slightly modified within `FileFacade`, moving the callable array into local variable first to allow phpstan properly deal with it. That allows us to remove error pattern ignore from the baseline instead of recreating it with a changed message. On top, a small typo (casing) in `runTests.sh` is fixed along the way to write the updated baselines to the correct paths. Used command(s): ```shell Build/Scripts/runTests.sh -p 8.1 -t 11 -s phpstanGenerateBaseline && \ Build/Scripts/runTests.sh -p 8.2 -t 12 -s phpstanGenerateBaseline ``` [1] https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.5/Deprecation-95222-ExtbaseViewInterface.html Resolves: #22
1 parent 5e9260a commit f76dce7

5 files changed

Lines changed: 14 additions & 20 deletions

File tree

Build/Scripts/runTests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ case ${TEST_SUITE} in
617617
;;
618618
phpstanGenerateBaseline)
619619
PHPSTAN_CONFIG_FILE="Build/phpstan/core${CORE_VERSION}/phpstan.neon"
620-
COMMAND=(php -dxdebug.mode=off .Build/bin/phpstan analyse -c ${PHPSTAN_CONFIG_FILE} --no-progress --no-interaction --memory-limit 4G --allow-empty-baseline --generate-baseline=Build/phpstan/Core${CORE_VERSION}/phpstan-baseline.neon)
620+
COMMAND=(php -dxdebug.mode=off .Build/bin/phpstan analyse -c ${PHPSTAN_CONFIG_FILE} --no-progress --no-interaction --memory-limit 4G --allow-empty-baseline --generate-baseline=Build/phpstan/core${CORE_VERSION}/phpstan-baseline.neon)
621621
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name phpstan-baseline-${SUFFIX} -e COMPOSER_CACHE_DIR=.Build/.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} "${COMMAND[@]}"
622622
SUITE_EXIT_CODE=$?
623623
;;

Build/phpstan/core11/phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ parameters:
145145
count: 1
146146
path: ../../../Classes/FileFacade.php
147147

148-
-
149-
message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface, string\\} given\\.$#"
150-
count: 1
151-
path: ../../../Classes/FileFacade.php
152-
153148
-
154149
message: "#^Property WebVision\\\\WvFileCleanup\\\\FileFacade\\:\\:\\$databaseConnection has no type specified\\.$#"
155150
count: 1

Build/phpstan/core12/phpstan-baseline.neon

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ parameters:
6565
count: 1
6666
path: ../../../Classes/Controller/CleanupController.php
6767

68+
-
69+
message: "#^Method WebVision\\\\WvFileCleanup\\\\Controller\\\\CleanupController\\:\\:initializeView\\(\\) has parameter \\$view with no type specified\\.$#"
70+
count: 1
71+
path: ../../../Classes/Controller/CleanupController.php
72+
6873
-
6974
message: "#^PHPDoc tag @var has invalid value \\(\\$resourceFactory ResourceFactory \\*\\)\\: Unexpected token \"\\$resourceFactory\", expected type at offset 9$#"
7075
count: 2
@@ -85,11 +90,6 @@ parameters:
8590
count: 1
8691
path: ../../../Classes/Controller/CleanupController.php
8792

88-
-
89-
message: "#^Parameter \\$view of method WebVision\\\\WvFileCleanup\\\\Controller\\\\CleanupController\\:\\:initializeView\\(\\) has invalid type TYPO3\\\\CMS\\\\Extbase\\\\Mvc\\\\View\\\\ViewInterface\\.$#"
90-
count: 1
91-
path: ../../../Classes/Controller/CleanupController.php
92-
9393
-
9494
message: "#^Property WebVision\\\\WvFileCleanup\\\\Controller\\\\CleanupController\\:\\:\\$moduleSettings type has no value type specified in iterable type array\\.$#"
9595
count: 1
@@ -160,11 +160,6 @@ parameters:
160160
count: 1
161161
path: ../../../Classes/FileFacade.php
162162

163-
-
164-
message: "#^Parameter \\#1 \\$callback of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface, string\\} given\\.$#"
165-
count: 1
166-
path: ../../../Classes/FileFacade.php
167-
168163
-
169164
message: "#^Property WebVision\\\\WvFileCleanup\\\\FileFacade\\:\\:\\$databaseConnection has no type specified\\.$#"
170165
count: 1

Classes/Controller/CleanupController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use TYPO3\CMS\Core\Resource\ResourceStorage;
2626
use TYPO3\CMS\Core\Utility\GeneralUtility;
2727
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
28-
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
2928
use WebVision\WvFileCleanup\Domain\Repository\FileRepository;
3029

3130
/**
@@ -64,7 +63,11 @@ public function initializeAction(): void
6463
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
6564
}
6665

67-
public function initializeView(ViewInterface $view): void
66+
/**
67+
* Note that `$view` does not have native type declaration by intention to follow the recommended migration path for
68+
* https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.5/Deprecation-95222-ExtbaseViewInterface.html.
69+
*/
70+
public function initializeView($view): void
6871
{
6972
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
7073
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/WvFileCleanup/Cleanup');

Classes/FileFacade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ public function getLastReferenceTimestamp()
287287
*/
288288
public function __call($method, $arguments)
289289
{
290-
if (is_callable([$this->resource, $method])) {
291-
return call_user_func_array([$this->resource, $method], $arguments);
290+
$resourceMethod = [$this->resource, $method];
291+
if (is_callable($resourceMethod)) {
292+
return call_user_func_array($resourceMethod, $arguments);
292293
}
293294

294295
return null;

0 commit comments

Comments
 (0)