Completed
Push — master ( 6ba652...6f597b )
by Vitaly
02:20
created

AnnotationMethodResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 9 2
A resolveMethodAnnotations() 0 17 3
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\metadata\ClassMetadata;
10
use samsonframework\container\metadata\MethodMetadata;
11
12
/**
13
 * Class method annotation resolver.
14
 */
15
class AnnotationMethodResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20
    public function resolve(\ReflectionClass $classData, ClassMetadata $classMetadata)
21
    {
22
        /** @var \ReflectionMethod $method */
23
        foreach ($classData->getMethods() as $method) {
24
            $this->resolveMethodAnnotations($method, $classMetadata);
25
        }
26
27
        return $this->classMetadata;
28
    }
29
30
    /**
31
     * Resolve class method annotations.
32
     *
33
     * @param \ReflectionMethod $method
34
     * @param ClassMetadata     $classMetadata
35
     */
36
    protected function resolveMethodAnnotations(\ReflectionMethod $method, ClassMetadata $classMetadata)
37
    {
38
        // Create method metadata instance
39
        $methodMetadata = new MethodMetadata();
40
        $methodMetadata->name = $method->getName();
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
41
        $methodMetadata->modifiers = $method->getModifiers();
42
        $methodMetadata->parameters = $method->getParameters();
43
44
        /** @var MethodInterface $annotation */
45
        foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
46
            if ($annotation instanceof MethodInterface) {
47
                $methodMetadata->options[] = $annotation->toMethodMetadata($methodMetadata);
48
            }
49
        }
50
51
        $classMetadata->methodsMetadata[$method->getName()] = $methodMetadata;
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
52
    }
53
}
54