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

AnnotationClassResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 15 2
A resolveClassAnnotations() 0 9 3
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 samsonframework\container\annotation\ClassInterface;
11
use samsonframework\container\metadata\ClassMetadata;
12
13
/**
14
 * Annotation resolver class.
15
 */
16
class AnnotationClassResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function resolve(\ReflectionClass $classData, ClassMetadata $classMetadata)
22
    {
23
        /** @var \ReflectionClass $classData */
24
25
        // Create and fill class metadata base fields
26
        $classMetadata = new ClassMetadata();
27
        $classMetadata->className = $classData->getName();
0 ignored issues
show
Bug introduced by
Consider using $classData->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
28
        $classMetadata->nameSpace = $classData->getNamespaceName();
29
        $classMetadata->identifier = $identifier ?: uniqid();
0 ignored issues
show
Bug introduced by
The variable $identifier does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
        $classMetadata->name = $classMetadata->identifier;
31
32
        $this->resolveClassAnnotations($classData, $classMetadata);
33
34
        return $classMetadata;
35
    }
36
37
    /**
38
     * Resolve all class annotations.
39
     *
40
     * @param \ReflectionClass $classData
41
     * @param ClassMetadata    $metadata
42
     */
43
    protected function resolveClassAnnotations(\ReflectionClass $classData, ClassMetadata $metadata)
44
    {
45
        /** @var ClassInterface $annotation Read class annotations */
46
        foreach ($this->reader->getClassAnnotations($classData) as $annotation) {
47
            if ($annotation instanceof ClassInterface) {
48
                $annotation->toClassMetadata($metadata);
49
            }
50
        }
51
    }
52
}
53