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

resolveMethodAnnotations()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 5
Bugs 2 Features 1
Metric Value
c 5
b 2
f 1
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 8.5806
cc 4
eloc 15
nc 6
nop 2
crap 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