Completed
Push — master ( 7d2cf1...09c073 )
by Vitaly
02:33
created

Route   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 69.23%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 44
ccs 9
cts 13
cp 0.6923
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A toMethodMetadata() 0 4 1
A toClassMetadata() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Vitaly Iegorov
5
 * Date: 07.08.2016
6
 * Time: 11:55.
7
 */
8
namespace samsonframework\container\annotation;
9
10
use samsonframework\container\metadata\ClassMetadata;
11
use samsonframework\container\metadata\MethodMetadata;
12
13
/**
14
 * Class Route.
15
 *
16
 * @Annotation
17
 */
18
class Route extends CollectionValue implements ClassInterface, MethodInterface
19
{
20
    /** @var string Route path */
21
    protected $path;
22
23
    /** @var string Route identifier */
24
    protected $identifier;
25
26
    /**
27
     * Route constructor.
28
     *
29
     * @param array $valueOrValues
30
     *
31
     * @throws \InvalidArgumentException
32
     */
33 1
    public function __construct($valueOrValues)
34
    {
35 1
        parent::__construct($valueOrValues);
36
37 1
        if (!array_key_exists('value', $valueOrValues) || $valueOrValues['value'] === '') {
38
            throw new \InvalidArgumentException('@Route annotation should have value');
39
        }
40
41
        // Set data
42 1
        $this->path = $valueOrValues['value'] ?? null;
43 1
        $this->identifier = $valueOrValues['name'] ?? uniqid(__CLASS__, true);
44 1
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 1
    public function toMethodMetadata(MethodMetadata $methodMetadata)
50
    {
51 1
        $methodMetadata->routes[$this->identifier] = $this->path;
52 1
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function toClassMetadata(ClassMetadata $classMetadata)
58
    {
59
        $classMetadata->routes[$this->identifier] = $this->path;
60
    }
61
}
62