Reflection   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 1
dl 0
loc 75
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getClassAnnotations() 0 4 1
A getMethodsAnnotations() 0 4 1
A getPropertiesAnnotations() 0 4 1
A getMethodAnnotations() 0 8 2
A getPropertyAnnotations() 0 8 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Leaditin\Annotations;
6
7
use Leaditin\Annotations\Exception\ReflectionException;
8
9
/**
10
 * Class Reflection
11
 *
12
 * @package Leaditin\Annotations
13
 * @author Igor Vuckovic <[email protected]>
14
 */
15
class Reflection
16
{
17
    /** @var Collection|Annotation[] */
18
    protected $annotationsFromClass;
19
20
    /** @var Collection[] */
21
    protected $annotationsFromMethods;
22
23
    /** @var Collection[] */
24
    protected $annotationsFromProperties;
25
26
    /**
27
     * @param Collection $annotationsFromClass
28
     * @param Collection[] $annotationsFromMethods
29
     * @param Collection[] $annotationsFromProperties
30
     */
31 14
    public function __construct(Collection $annotationsFromClass, array $annotationsFromMethods, array $annotationsFromProperties)
32
    {
33 14
        $this->annotationsFromClass = $annotationsFromClass;
34 14
        $this->annotationsFromMethods = $annotationsFromMethods;
35 14
        $this->annotationsFromProperties = $annotationsFromProperties;
36 14
    }
37
38
    /**
39
     * @return Collection|Annotation[]
40
     */
41 2
    public function getClassAnnotations() : Collection
42
    {
43 2
        return $this->annotationsFromClass;
44
    }
45
46
    /**
47
     * @return Collection[]
48
     */
49 1
    public function getMethodsAnnotations() : array
50
    {
51 1
        return $this->annotationsFromMethods;
52
    }
53
54
    /**
55
     * @return Collection[]
56
     */
57 1
    public function getPropertiesAnnotations() : array
58
    {
59 1
        return $this->annotationsFromProperties;
60
    }
61
62
    /**
63
     * @param string $method
64
     * @return Collection|Annotation[]
65
     * @throws ReflectionException
66
     */
67 6
    public function getMethodAnnotations(string $method) : Collection
68
    {
69 6
        if (!array_key_exists($method, $this->annotationsFromMethods)) {
70 1
            throw ReflectionException::undefinedMethodAnnotations($method);
71
        }
72
73 5
        return $this->annotationsFromMethods[$method];
74
    }
75
76
    /**
77
     * @param string $property
78
     * @return Collection|Annotation[]
79
     * @throws ReflectionException
80
     */
81 3
    public function getPropertyAnnotations(string $property) : Collection
82
    {
83 3
        if (!array_key_exists($property, $this->annotationsFromProperties)) {
84 1
            throw ReflectionException::undefinedPropertyAnnotations($property);
85
        }
86
87 2
        return $this->annotationsFromProperties[$property];
88
    }
89
}
90