From e6c6ab3aafed936804fcb38c350c92c8e433c9ab Mon Sep 17 00:00:00 2001 From: Chuck Burgess Date: Mon, 12 Feb 2018 08:07:11 -0600 Subject: [PATCH 1/2] handle additional \Reflector child types; --- src/Types/ContextFactory.php | 49 +++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index 13bb8fd..e88613b 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -12,6 +12,9 @@ namespace phpDocumentor\Reflection\Types; +use phpDocumentor\Reflection\DocBlock\Context; +use UnexpectedValueException; + /** * Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor. * @@ -33,31 +36,53 @@ final class ContextFactory * Build a Context given a Class Reflection. * * @see Context for more information on Contexts. - * @return Context */ - public function createFromReflector(\Reflector $reflector) + public function createFromReflector(\Reflector $reflector): Context { + if ($reflector instanceof \ReflectionClass) { + return $this->createFromReflectionClass($reflector); + } + + if ($reflector instanceof \ReflectionParameter) { + return $this->createFromReflectionParameter($reflector); + } + if ($reflector instanceof \ReflectionMethod) { return $this->createFromReflectionMethod($reflector); } - if ($reflector instanceof \ReflectionClass) { - return $this->createFromReflectionClass($reflector); + if ($reflector instanceof \ReflectionProperty) { + return $this->createFromReflectionProperty($reflector); } + + if ($reflector instanceof \ReflectionClassConstant) { + return $this->createFromReflectionClassConstant($reflector); + } + + throw new UnexpectedValueException('Unhandled \Reflector instance given: ' . get_class($reflector)); } - /** - * @return Context - */ - private function createFromReflectionMethod(\ReflectionMethod $method) + private function createFromReflectionParameter(\ReflectionParameter $parameter): Context + { + return $this->createFromReflectionClass($parameter->getDeclaringClass()); + } + + private function createFromReflectionMethod(\ReflectionMethod $method): Context { return $this->createFromReflectionClass($method->getDeclaringClass()); } - /** - * @return Context - */ - private function createFromReflectionClass(\ReflectionClass $class) + private function createFromReflectionProperty(\ReflectionProperty $property): Context + { + return $this->createFromReflectionClass($property->getDeclaringClass()); + } + + private function createFromReflectionClassConstant(\ReflectionClassConstant $constant): Context + { + return $this->createFromReflectionClass($constant->getDeclaringClass()); + } + + private function createFromReflectionClass(\ReflectionClass $class): Context { $fileName = $class->getFileName(); $namespace = $class->getNamespaceName(); From 2d7825758e59fd04fabb03a342f4db57caf1e4bd Mon Sep 17 00:00:00 2001 From: Chuck Burgess Date: Mon, 12 Feb 2018 08:22:49 -0600 Subject: [PATCH 2/2] wrong Context class imported; --- src/Types/ContextFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index e88613b..ba25719 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -12,7 +12,6 @@ namespace phpDocumentor\Reflection\Types; -use phpDocumentor\Reflection\DocBlock\Context; use UnexpectedValueException; /**