Completed
Push — master ( daa27a...019907 )
by Vitaly
03:25
created

AnnotationMethodResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 48
ccs 20
cts 20
cp 1
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\configurator\MethodConfiguratorInterface;
11
use samsonframework\container\metadata\ClassMetadata;
12
use samsonframework\container\metadata\MethodMetadata;
13
use samsonframework\container\metadata\ParameterMetadata;
14
15
/**
16
 * Class method annotation resolver.
17
 */
18
class AnnotationMethodResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface
19
{
20
    /**
21
     * {@inheritDoc}
22
     */
23 11
    public function resolve(\ReflectionClass $classReflection, ClassMetadata $classMetadata)
24
    {
25
        /** @var \ReflectionMethod $method */
26 11
        foreach ($classReflection->getMethods() as $method) {
27 10
            $this->resolveMethodAnnotations($method, $classMetadata);
28
        }
29
30 11
        return $classMetadata;
31
    }
32
33
    /**
34
     * Resolve class method annotations.
35
     *
36
     * @param \ReflectionMethod $method
37
     * @param ClassMetadata     $classMetadata
38
     */
39 10
    protected function resolveMethodAnnotations(\ReflectionMethod $method, ClassMetadata $classMetadata)
40
    {
41
        // Create method metadata instance
42 10
        $methodMetadata = new MethodMetadata($classMetadata);
43 10
        $methodMetadata->name = $method->name;
44 10
        $methodMetadata->modifiers = $method->getModifiers();
45 10
        $methodMetadata->isPublic = $method->isPublic();
46
47
        /** @var \ReflectionParameter $parameter */
48 10
        $parameterMetadata = new ParameterMetadata($classMetadata, $methodMetadata);
49 10
        foreach ($method->getParameters() as $parameter) {
50 10
            $parameterMetadata = clone $parameterMetadata;
51 10
            $parameterMetadata->name = $parameter->name;
52 10
            $parameterMetadata->typeHint = (string)$parameter->getType();
53 10
            $methodMetadata->parametersMetadata[$parameterMetadata->name] = $parameterMetadata;
54
        }
55
56
        /** @var MethodInterface $annotation */
57 10
        foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
58 10
            if ($annotation instanceof MethodConfiguratorInterface) {
59 10
                $annotation->toMethodMetadata($methodMetadata);
60
            }
61
        }
62
63 10
        $classMetadata->methodsMetadata[$methodMetadata->name] = $methodMetadata;
64 10
    }
65
}
66