Commit f9f3dcbf authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Stefan Bürk
Browse files

[BUGFIX] Correct type annotation of GU::callUserFunction()

The argument `$funcName` is now annotated as `non-empty-string|\Closure`
to reflect the actual allowed input types. Additionally corresponding
test in `GeneralUtilityTest.php` is also annotated properly.

Used command:

> Build/Scripts/runTests.sh -s phpstanGenerateBaseline

Resolves: #97568
Releases: main, 11.5
Change-Id: I7ce640d3565f099e6dc5ba62c59e5616dc4dc6e4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74535

Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent f846c5e4
......@@ -1665,11 +1665,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Utility/GeneralUtility.php
-
message: "#^Call to function is_object\\(\\) with string will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/GeneralUtility.php
-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:getMaxUploadFileSize\\(\\) should return int but returns float\\.$#"
count: 1
......@@ -1690,11 +1685,6 @@ parameters:
count: 3
path: ../../typo3/sysext/core/Classes/Utility/GeneralUtility.php
-
message: "#^Result of && is always false\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/GeneralUtility.php
-
message: "#^Template type T of method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:makeInstance\\(\\) is not referenced in a parameter\\.$#"
count: 1
......@@ -2290,11 +2280,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
-
message: "#^Parameter \\#1 \\$funcName of static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:callUserFunction\\(\\) expects string, Closure given\\.$#"
count: 2
path: ../../typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
-
message: "#^Static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:callUserFunction\\(\\) invoked with 4 parameters, 2\\-3 required\\.$#"
count: 1
......
......@@ -2825,7 +2825,7 @@ class GeneralUtility
* Calls a user-defined function/method in class
* Such a function/method should look like this: "function proc(&$params, &$ref) {...}"
*
* @param string $funcName Function/Method reference or Closure.
* @param non-empty-string|\Closure $funcName Function/Method reference or Closure.
* @param mixed $params Parameters to be pass along (typically an array) (REFERENCE!)
* @param object|null $ref Reference to be passed along (typically "$this" - being a reference to the calling object)
* @return mixed Content from method/function call
......@@ -2861,6 +2861,7 @@ class GeneralUtility
// It's a function
$content = call_user_func_array($funcName, [&$params, &$ref]);
} else {
// Usually this will be annotated by static code analysis tools, but there's no native "not empty string" type
throw new \InvalidArgumentException('No function named: ' . $funcName, 1294585867);
}
return $content;
......
......@@ -3587,7 +3587,7 @@ class GeneralUtilityTest extends UnitTestCase
/**
* @test
* @dataProvider callUserFunctionInvalidParameterDataprovider
* @param string $functionName
* @param non-empty-string $functionName
* @param int $expectedException
*/
public function callUserFunctionWillThrowExceptionForInvalidParameters(string $functionName, int $expectedException): void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment