From fa4671f0c72c62ebf3aaaf6f35068f527e4934f7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Sep 2019 09:31:48 +0200 Subject: [PATCH] Removed the need to handle `ReflectionFunctionAbstract` in `DocBlock` ctor Instead, relying on either `ReflectionMethod` or `ReflectionClass` is more than enough. --- src/Annotation/DocBlock.php | 20 +++++++++----------- src/Annotation/Registry.php | 2 +- tests/unit/Util/TestTest.php | 18 +++++++++--------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Annotation/DocBlock.php b/src/Annotation/DocBlock.php index 0f017c01dd8..3b6bb9b771e 100644 --- a/src/Annotation/DocBlock.php +++ b/src/Annotation/DocBlock.php @@ -105,19 +105,17 @@ public static function ofClass(\ReflectionClass $class) : self ); } - public static function ofFunction(\ReflectionFunctionAbstract $function) : self + public static function ofMethod(\ReflectionMethod $method) : self { return new self( - (string) $function->getDocComment(), - $function instanceof \ReflectionMethod, - self::extractAnnotationsFromReflector($function), - $function->getStartLine(), - $function->getEndLine(), - $function->getFileName(), - $function->getName(), - $function instanceof \ReflectionMethod - ? $function->getDeclaringClass()->getName() - : null + (string) $method->getDocComment(), + true, + self::extractAnnotationsFromReflector($method), + $method->getStartLine(), + $method->getEndLine(), + $method->getFileName(), + $method->getName(), + $method->getDeclaringClass()->getName() ); } diff --git a/src/Annotation/Registry.php b/src/Annotation/Registry.php index 74f2e541560..1ca0d4e591e 100644 --- a/src/Annotation/Registry.php +++ b/src/Annotation/Registry.php @@ -85,6 +85,6 @@ public function forMethod(string $class, string $method) : DocBlock ); } - return $this->methodDocBlocks[$class][$method] = DocBlock::ofFunction($reflection); + return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection); } } diff --git a/tests/unit/Util/TestTest.php b/tests/unit/Util/TestTest.php index 6a48dc1d423..3baa22f5d3f 100644 --- a/tests/unit/Util/TestTest.php +++ b/tests/unit/Util/TestTest.php @@ -938,7 +938,7 @@ public function testWithDuplicateKeyDataProviders(): void public function testTestWithEmptyAnnotation(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'anotherAnnotation' ))->getProvidedData(); @@ -948,7 +948,7 @@ public function testTestWithEmptyAnnotation(): void public function testTestWithSimpleCase(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith1' ))->getProvidedData(); @@ -958,7 +958,7 @@ public function testTestWithSimpleCase(): void public function testTestWithMultiLineMultiParameterCase(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith1234' ))->getProvidedData(); @@ -968,7 +968,7 @@ public function testTestWithMultiLineMultiParameterCase(): void public function testTestWithVariousTypes(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithABTrueNull' ))->getProvidedData(); @@ -978,7 +978,7 @@ public function testTestWithVariousTypes(): void public function testTestWithAnnotationAfter(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith12AndAnotherAnnotation' ))->getProvidedData(); @@ -988,7 +988,7 @@ public function testTestWithAnnotationAfter(): void public function testTestWithSimpleTextAfter(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith12AndBlahBlah' ))->getProvidedData(); @@ -998,7 +998,7 @@ public function testTestWithSimpleTextAfter(): void public function testTestWithCharacterEscape(): void { - $result = DocBlock::ofFunction(new \ReflectionMethod( + $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithEscapedString' ))->getProvidedData(); @@ -1008,7 +1008,7 @@ public function testTestWithCharacterEscape(): void public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed(): void { - $docBlock = DocBlock::ofFunction(new \ReflectionMethod( + $docBlock = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithMalformedValue' )); @@ -1021,7 +1021,7 @@ public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed(): void public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParsed(): void { - $docBlock = DocBlock::ofFunction(new \ReflectionMethod( + $docBlock = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithWellFormedAndMalformedValue' ));