From 48333044faa315cba92a24ca44ca67fe778c3cad Mon Sep 17 00:00:00 2001 From: kschatzle Date: Fri, 9 Sep 2022 13:47:16 -0500 Subject: [PATCH] Initial compatability support for PHP8.2 for disjunctive normal form arguments and return types. DNF arguments and return types will throw ClassMirrorException's. --- fixtures/DnfArgumentType.php | 11 ++++++++ fixtures/DnfReturnType.php | 11 ++++++++ .../Doubler/Generator/ClassMirror.php | 7 +++++ tests/Doubler/Generator/ClassMirrorTest.php | 28 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 fixtures/DnfArgumentType.php create mode 100644 fixtures/DnfReturnType.php diff --git a/fixtures/DnfArgumentType.php b/fixtures/DnfArgumentType.php new file mode 100644 index 000000000..494b39295 --- /dev/null +++ b/fixtures/DnfArgumentType.php @@ -0,0 +1,11 @@ +getTypes(); + if (\PHP_VERSION_ID >= 80200) { + foreach ($types as $reflectionType) { + if ($reflectionType instanceof ReflectionIntersectionType) { + throw new ClassMirrorException('Doubling intersection types is not supported', $class); + } + } + } } elseif ($type instanceof ReflectionIntersectionType) { throw new ClassMirrorException('Doubling intersection types is not supported', $class); diff --git a/tests/Doubler/Generator/ClassMirrorTest.php b/tests/Doubler/Generator/ClassMirrorTest.php index 03f5964ec..fc19b9bca 100644 --- a/tests/Doubler/Generator/ClassMirrorTest.php +++ b/tests/Doubler/Generator/ClassMirrorTest.php @@ -645,4 +645,32 @@ public function it_can_not_double_intersection_argument_types() $classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\IntersectionArgumentType'), []); } + + /** + * @test + */ + public function it_can_not_double_dnf_intersection_argument_types() + { + if (PHP_VERSION_ID < 80200) { + $this->markTestSkipped('DNF intersection types are not supported in this PHP version'); + } + + $this->expectException(ClassMirrorException::class); + + $classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\DnfArgumentType'), []); + } + + /** + * @test + */ + public function it_can_not_double_dnf_intersection_return_types() + { + if (PHP_VERSION_ID < 80200) { + $this->markTestSkipped('DNF intersection types are not supported in this PHP version'); + } + + $this->expectException(ClassMirrorException::class); + + $classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\DnfReturnType'), []); + } }