Skip to content
Snippets Groups Projects
Commit 0eaded70 authored by Garvin Hicking's avatar Garvin Hicking
Browse files

[BUGFIX] Prevent type error in Extension Scanner

Several extension scanner matchers scan a
MethodCall node type, but cannot deal with possible
method concatenation.

Concatenating method names may involve dynamic
variable resolving, which static analysis cannot
perform. Thus, it is a setup for failure to
try this.

Instead this patch gracefully ignores these method
calls to not throw a PHP type error on scanning
extensions.

Teachable moment: Try to not use dynamic method
calls like

```
$dynamic = '1';
$this->{'like' . $dynamic}($arg1, $arg2, $arg3);
```

Resolves: #106043
Releases: main, 13.4, 12.4
Change-Id: I20a2953d649ea7377492eed489965f617b1069ae
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88046


Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarGarvin Hicking <gh@faktor-e.de>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarGarvin Hicking <gh@faktor-e.de>
parent 0bdcf915
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ class InterfaceMethodChangedMatcher extends AbstractCoreMatcher
// Match method call (not static) with number of arguments
if ($node instanceof MethodCall
&& array_key_exists($node->name->name, $this->matcherDefinitions)
&& isset($node->name->name) && array_key_exists($node->name->name, $this->matcherDefinitions)
) {
$methodName = $node->name->name;
$numberOfUsedArguments = 0;
......
......@@ -51,6 +51,7 @@ class MethodArgumentDroppedMatcher extends AbstractCoreMatcher
if (!$this->isFileIgnored($node)
&& !$this->isLineIgnored($node)
&& $node instanceof MethodCall
&& isset($node->name->name)
&& array_key_exists($node->name->name, $this->flatMatcherDefinitions)
) {
$match = [
......
......@@ -50,6 +50,7 @@ class MethodArgumentRequiredMatcher extends AbstractCoreMatcher
if (!$this->isFileIgnored($node)
&& !$this->isLineIgnored($node)
&& $node instanceof MethodCall
&& isset($node->name->name)
&& array_key_exists($node->name->name, $this->flatMatcherDefinitions)
) {
$match = [
......
......@@ -52,6 +52,7 @@ class MethodArgumentUnusedMatcher extends AbstractCoreMatcher
if (!$this->isFileIgnored($node)
&& !$this->isLineIgnored($node)
&& $node instanceof MethodCall
&& isset($node->name->name)
&& array_key_exists($node->name->name, $this->flatMatcherDefinitions)
) {
$match = [
......
......@@ -67,6 +67,7 @@ class MethodCallArgumentValueMatcher extends AbstractCoreMatcher
$matchCandidate = [$this->matcherDefinitions[$node->class->toString() . '::' . $node->name->name]];
} elseif ($node instanceof MethodCall
&& isset($node->name->name)
&& array_key_exists($node->name->name, $this->flatMatcherDefinitions)
) {
$match = [
......
......@@ -50,6 +50,7 @@ class MethodCallMatcher extends AbstractCoreMatcher
if (!$this->isFileIgnored($node)
&& !$this->isLineIgnored($node)
&& $node instanceof MethodCall
&& isset($node->name->name)
&& array_key_exists($node->name->name, $this->flatMatcherDefinitions)
) {
$match = [
......
......@@ -81,4 +81,17 @@ class InterfaceMethodChangedMatcherFixture
* @param $arg3
*/
protected function like5($arg1, $arg2, $arg3): void {}
/**
* No match: Protected, no error thrown
*
* @param $arg1
* @param $arg2
* @param $arg3
*/
protected function concatenatedCall($arg1, $arg2, $arg3): void
{
$dynamic = '1';
$this->{'like' . $dynamic}($arg1, $arg2, $arg3);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment