Skip to content

Commit

Permalink
[TASK] Harden event listener automagic parameter type resolution
Browse files Browse the repository at this point in the history
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 <bfr@qbus.de>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
  • Loading branch information
bnf committed Jan 31, 2022
1 parent 1dafc1e commit ae8010b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
5 changes: 0 additions & 5 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -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
Expand Down
Expand Up @@ -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,
Expand Down

0 comments on commit ae8010b

Please sign in to comment.