Completed
Push — master ( 692093...daa27a )
by Vitaly
02:57
created

AnnotationMethodResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 80%

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 48
ccs 16
cts 20
cp 0.8
rs 10
c 7
b 2
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 9 2
B resolveMethodAnnotations() 0 26 4
1
<?php
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 07.08.16 at 13:04
5
 */
6
namespace samsonframework\container\resolver;
7
8
use samsonframework\container\annotation\MethodInterface;
9
use samsonframework\container\annotation\ParameterInterface;
10
use samsonframework\container\metadata\ClassMetadata;
11
use samsonframework\container\metadata\MethodMetadata;
12
use samsonframework\container\metadata\ParameterMetadata;
13
14
/**
15
 * Class method annotation resolver.
16
 */
17
class AnnotationMethodResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22 9
    public function resolve(\ReflectionClass $classReflection, ClassMetadata $classMetadata)
23
    {
24
        /** @var \ReflectionMethod $method */
25 9
        foreach ($classReflection->getMethods() as $method) {
26 8
            $this->resolveMethodAnnotations($method, $classMetadata);
27
        }
28
29 1
        return $classMetadata;
30
    }
31
32
    /**
33
     * Resolve class method annotations.
34
     *
35
     * @param \ReflectionMethod $method
36
     * @param ClassMetadata     $classMetadata
37
     */
38 8
    protected function resolveMethodAnnotations(\ReflectionMethod $method, ClassMetadata $classMetadata)
39
    {
40
        // Create method metadata instance
41 8
        $methodMetadata = new MethodMetadata($classMetadata);
42 8
        $methodMetadata->name = $method->name;
43 8
        $methodMetadata->modifiers = $method->getModifiers();
44 8
        $methodMetadata->isPublic = $method->isPublic();
45
46
        /** @var \ReflectionParameter $parameter */
47 8
        $parameterMetadata = new ParameterMetadata($classMetadata, $methodMetadata);
48 8
        foreach ($method->getParameters() as $parameter) {
49 8
            $parameterMetadata = clone $parameterMetadata;
50 8
            $parameterMetadata->name = $parameter->name;
51 8
            $parameterMetadata->typeHint = (string)$parameter->getType();
52 8
            $methodMetadata->parametersMetadata[$parameterMetadata->name] = $parameterMetadata;
53
        }
54
55
        /** @var MethodInterface $annotation */
56 8
        foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
57
            if ($annotation instanceof MethodInterface) {
58
                $annotation->toMethodMetadata($methodMetadata);
59
            }
60
        }
61
62
        $classMetadata->methodsMetadata[$methodMetadata->name] = $methodMetadata;
63
    }
64
}
65