StandardReflector   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 64
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 4 1
A getCtor() 0 6 1
A getCtorParams() 0 6 2
B getParamTypeHint() 0 15 5
A getFunction() 0 4 1
A getMethod() 0 8 2
A getDocBlock() 0 12 1
1
<?php
2
3
namespace Atreyu;
4
5
use phpDocumentor\Reflection\DocBlock;
6
use phpDocumentor\Reflection\DocBlock\Context;
7
8
class StandardReflector extends BaseReflector implements Reflector
9
{
10
    public function getClass($class)
11
    {
12
        return new ExtendedReflectionClass($class);
13
    }
14
15
    public function getCtor($class)
16
    {
17
        $reflectionClass = new ExtendedReflectionClass($class);
18
19
        return $reflectionClass->getConstructor();
20
    }
21
22
    public function getCtorParams($class)
23
    {
24
        return ($reflectedCtor = $this->getCtor($class))
25
            ? $reflectedCtor->getParameters()
26
            : null;
27
    }
28
29
    public function getParamTypeHint(\ReflectionFunctionAbstract $function, \ReflectionParameter $param, array $arguments = [])
30
    {
31
        if ($reflectionClass = $param->getClass()) {
32
            $typeHint = $reflectionClass->getName();
33
        } elseif (($function instanceof \ReflectionMethod)
34
            && ($docBlockParams = $this->getDocBlock($function)->getTagsByName('param'))
35
            && !empty($docBlockParams)
36
        ) {
37
            $typeHint = $this->getParamDocBlockHint($docBlockParams, $param, $arguments);
38
        } else {
39
            $typeHint = null;
40
        }
41
42
        return $typeHint;
43
    }
44
45
    public function getFunction($functionName)
46
    {
47
        return new \ReflectionFunction($functionName);
48
    }
49
50
    public function getMethod($classNameOrInstance, $methodName)
51
    {
52
        $className = is_string($classNameOrInstance)
53
            ? $classNameOrInstance
54
            : get_class($classNameOrInstance);
55
56
        return new \ReflectionMethod($className, $methodName);
57
    }
58
59
    public function getDocBlock(\ReflectionMethod $method)
60
    {
61
        $class = $this->getClass($method->class);
62
63
        return new DocBlock(
64
            $method->getDocComment(),
65
            new Context(
66
                $class->getNamespaceName(),
67
                $class->getUseStatements()
68
            )
69
        );
70
    }
71
}
72