From e3a0e0d1b968c4338d2a50d76562c49e49521565 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sat, 6 Nov 2021 16:33:44 +0100 Subject: [PATCH] ReflectionEnum runtime stubs (PHP 8.0+) --- src/Command/CommandHelper.php | 8 +++++ .../ClassBlacklistReflectionProvider.php | 12 ++++++- src/Testing/PHPStanTestCase.php | 8 +++++ stubs/runtime/Enum/BackedEnum.php | 14 ++++++++ stubs/runtime/Enum/ReflectionEnum.php | 32 +++++++++++++++++++ .../runtime/Enum/ReflectionEnumBackedCase.php | 14 ++++++++ stubs/runtime/Enum/ReflectionEnumUnitCase.php | 25 +++++++++++++++ stubs/runtime/Enum/UnitEnum.php | 15 +++++++++ 8 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 stubs/runtime/Enum/BackedEnum.php create mode 100644 stubs/runtime/Enum/ReflectionEnum.php create mode 100644 stubs/runtime/Enum/ReflectionEnumBackedCase.php create mode 100644 stubs/runtime/Enum/ReflectionEnumUnitCase.php create mode 100644 stubs/runtime/Enum/UnitEnum.php diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 6eecec6300..9039c480f0 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -326,6 +326,14 @@ public static function begin( self::executeBootstrapFile($bootstrapFileFromArray, $container, $errorOutput, $debugEnabled); } + if (PHP_VERSION_ID >= 80000) { + require_once __DIR__ . '/../../stubs/runtime/Enum/UnitEnum.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/BackedEnum.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnum.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumUnitCase.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumBackedCase.php'; + } + foreach ($container->getParameter('scanFiles') as $scannedFile) { if (is_file($scannedFile)) { continue; diff --git a/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php b/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php index 1d6c2ce2e9..a53a309438 100644 --- a/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php +++ b/src/Reflection/ReflectionProvider/ClassBlacklistReflectionProvider.php @@ -79,7 +79,17 @@ private function isClassBlacklisted(string $className): bool if (!class_exists($className, false)) { return true; } - if (in_array(strtolower($className), ['reflectionuniontype', 'attribute', 'returntypewillchange', 'reflectionintersectiontype'], true)) { + if (in_array(strtolower($className), [ + 'reflectionuniontype', + 'attribute', + 'returntypewillchange', + 'reflectionintersectiontype', + 'unitenum', + 'backedenum', + 'reflectionenum', + 'reflectionenumunitcase', + 'reflectionenumbackedcase', + ], true)) { return true; } $reflection = new \ReflectionClass($className); diff --git a/src/Testing/PHPStanTestCase.php b/src/Testing/PHPStanTestCase.php index b38b0fd015..2dbf880070 100644 --- a/src/Testing/PHPStanTestCase.php +++ b/src/Testing/PHPStanTestCase.php @@ -65,6 +65,14 @@ public static function getContainer(): Container require_once $file; })($bootstrapFile); } + + if (PHP_VERSION_ID >= 80000) { + require_once __DIR__ . '/../../stubs/runtime/Enum/UnitEnum.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/BackedEnum.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnum.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumUnitCase.php'; + require_once __DIR__ . '/../../stubs/runtime/Enum/ReflectionEnumBackedCase.php'; + } } return self::$containers[$cacheKey]; diff --git a/stubs/runtime/Enum/BackedEnum.php b/stubs/runtime/Enum/BackedEnum.php new file mode 100644 index 0000000000..c830ea24ff --- /dev/null +++ b/stubs/runtime/Enum/BackedEnum.php @@ -0,0 +1,14 @@ +