Skip to content

Commit

Permalink
Removed the need to handle ReflectionFunctionAbstract in DocBlock
Browse files Browse the repository at this point in the history
… ctor

Instead, relying on either `ReflectionMethod` or `ReflectionClass` is more
than enough.
  • Loading branch information
Ocramius authored and sebastianbergmann committed Sep 7, 2019
1 parent 41f25ba commit fa4671f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
20 changes: 9 additions & 11 deletions src/Annotation/DocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 9 additions & 9 deletions tests/unit/Util/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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'
));
Expand All @@ -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'
));
Expand Down

0 comments on commit fa4671f

Please sign in to comment.