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

AnnotationResolver::resolve()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 34
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 9.1595

Importance

Changes 7
Bugs 0 Features 6
Metric Value
c 7
b 0
f 6
dl 0
loc 34
ccs 10
cts 18
cp 0.5556
rs 8.439
cc 6
eloc 18
nc 18
nop 2
crap 9.1595
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