Completed
Push — master ( 57efb7...b06714 )
by Vitaly
02:51
created

AnnotationResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 61.9%

Importance

Changes 9
Bugs 1 Features 7
Metric Value
wmc 7
c 9
b 1
f 7
lcom 1
cbo 4
dl 0
loc 55
ccs 13
cts 21
cp 0.619
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B resolve() 0 34 6
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 29.07.2016
6
 * Time: 21:38.
7
 */
8
namespace samsonframework\container\resolver;
9
10
use Doctrine\Common\Annotations\AnnotationReader;
11
use samsonframework\container\annotation\MetadataInterface;
12
use samsonframework\container\annotation\MethodAnnotation;
13
use samsonframework\container\metadata\ClassMetadata;
14
use samsonframework\container\metadata\MethodMetadata;
15
16
class AnnotationResolver extends Resolver
17
{
18
    /**
19
     * @var CachedReader
20
     */
21
    protected $reader;
22
23
    /**
24
     * AnnotationResolver constructor.
25
     *
26
     * @throws \InvalidArgumentException
27
     */
28 1
    public function __construct()
29
    {
30 1
        $this->reader = new AnnotationReader();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Ann...ions\AnnotationReader() of type object<Doctrine\Common\A...tions\AnnotationReader> is incompatible with the declared type object<samsonframework\c...\resolver\CachedReader> of property $reader.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31 1
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 1
    public function resolve($classData, $identifier = null)
37
    {
38
        /** @var \ReflectionClass $classData */
39
40
        // Create and fill class metadata base fields
41 1
        $metadata = new ClassMetadata();
42 1
        $metadata->className = $classData->getName();
43 1
        $metadata->internalId = $identifier ?: uniqid();
44 1
        $metadata->name = $metadata->internalId;
45
46
        /** @var MetadataInterface $annotation Read class annotations */
47 1
        foreach ($this->reader->getClassAnnotations($classData) as $annotation) {
48 1
            if (class_implements($annotation, MetadataInterface::class)) {
49 1
                $annotation->toMetadata($metadata);
50
            }
51
        }
52
53
        /** @var \ReflectionMethod $method */
54 1
        foreach ($classData->getMethods() as $method) {
55
            $methodAnnotations = $this->reader->getMethodAnnotations($method);
56
            $methodMetadata = new MethodMetadata();
57
            $methodMetadata->name = $method->getName();
58
            $methodMetadata->modifiers = $method->getModifiers();
59
            $methodMetadata->parameters = $method->getParameters();
60
61
            /** @var MethodAnnotation $methodAnnotation */
62
            foreach ($methodAnnotations as $methodAnnotation) {
63
                $methodMetadata->options[$methodAnnotation->getMethodAlias()] = $methodAnnotation->convertToMetadata();
64
            }
65
            $metadata->methodsMetadata[$method->getName()] = $methodMetadata;
66
        }
67
68 1
        return $metadata;
69
    }
70
}
71