From ae8010bf80ace2d81f815849a8817f15f6931dc3 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Mon, 31 Jan 2022 08:47:44 +0100 Subject: [PATCH] [TASK] Harden event listener automagic parameter type resolution Do only auto-resolve the event name if the reflection type of the first parameter is a ReflectionNamedType [1] as only this subclass of ReflectionType defines the getName() method. [1] https://www.php.net/manual/en/class.reflectionnamedtype.php Commands executed: Build/Scripts/runTests.sh -s phpstanGenerateBaseline Releases: main, 11.5 Resolves: #96704 Change-Id: If30b04d68f182920a3736fa5333b9d996e989528 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73248 Tested-by: Benjamin Franzke Tested-by: core-ci Reviewed-by: Benjamin Franzke Reviewed-by: Oliver Klee --- Build/phpstan/phpstan-baseline.neon | 5 ----- .../Classes/DependencyInjection/ListenerProviderPass.php | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index cc5b93e3882e..e687132c7f95 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -1380,11 +1380,6 @@ parameters: count: 5 path: ../../typo3/sysext/core/Classes/Database/SoftReferenceIndex.php - - - message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#" - count: 1 - path: ../../typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php - - message: "#^Call to an undefined method ReflectionClass\\:\\:getAttributes\\(\\)\\.$#" count: 1 diff --git a/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php b/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php index 5228ab075a0f..ca5f63656458 100644 --- a/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php +++ b/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php @@ -117,7 +117,7 @@ protected function getParameterType(string $serviceName, Definition $definition, } $params = $this->getReflectionMethod($serviceName, $definition, $method)->getParameters(); $rType = count($params) ? $params[0]->getType() : null; - if ($rType === null) { + if (!$rType instanceof \ReflectionNamedType) { throw new \InvalidArgumentException( sprintf('Service "%s" registers method "%s" as an event listener, but does not specify an event type and the method does not type a parameter. Declare a class type for the method parameter or specify an event class explicitly', $serviceName, $method), 1623881315,