diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 24f6ea1228ea301a24b21eaead79c162f44a28c3..c9a4380fd3898b45fc7f19e7612ac886247eab58 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -2911,18 +2911,17 @@ class GeneralUtility * * @template T of object * @param class-string<T> $className name of the class to instantiate, must not be empty and not start with a backslash - * @param mixed $constructorArguments Arguments for the constructor * @return T the created instance * @throws \InvalidArgumentException if $className is empty or starts with a backslash */ - public static function makeInstance($className, ...$constructorArguments) + public static function makeInstance(string $className, mixed ...$constructorArguments): object { // PHPStan will complain about this check. That's okay as we're checking a contract violation here. - if (!is_string($className) || empty($className)) { + if ($className === '') { throw new \InvalidArgumentException('$className must be a non empty string.', 1288965219); } // Never instantiate with a beginning backslash, otherwise things like singletons won't work. - if ($className[0] === '\\') { + if (str_starts_with($className, '\\')) { throw new \InvalidArgumentException( '$className "' . $className . '" must not start with a backslash.', 1420281366 diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index c2688b98a57f0f7b3cada60c807eb967a2f64faf..6a4bb6775f73b9fbface8c8215f85b67fd5dd591 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -2922,54 +2922,6 @@ class GeneralUtilityTest extends UnitTestCase GeneralUtility::makeInstance(''); } - /** - * @test - */ - public function makeInstanceWithNullClassNameThrowsException(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionCode(1288965219); - - // @phpstan-ignore-next-line We're explicitly checking the behavior for a contract violation. - GeneralUtility::makeInstance(null); - } - - /** - * @test - */ - public function makeInstanceWithZeroStringClassNameThrowsException(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionCode(1288965219); - - // @phpstan-ignore-next-line We're explicitly checking the behavior for a contract violation. - GeneralUtility::makeInstance(0); - } - - /** - * @test - */ - public function makeInstanceWithEmptyArrayThrowsException(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionCode(1288965219); - - // @phpstan-ignore-next-line We're explicitly checking the behavior for a contract violation. - GeneralUtility::makeInstance([]); - } - - /** - * @test - */ - public function makeInstanceWithNonEmptyArrayThrowsException(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionCode(1288965219); - - // @phpstan-ignore-next-line We're explicitly checking the behavior for a contract violation. - GeneralUtility::makeInstance(['foo']); - } - /** * @test */