Skip to content

handle additional \Reflector child types; #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions src/Types/ContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace phpDocumentor\Reflection\Types;

use UnexpectedValueException;

/**
* Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor.
*
Expand All @@ -33,31 +35,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();
Expand Down