Completed
Pull Request — master (#5)
by Pavel
04:05
created

Method::setInherit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.02.2016
6
 * Time: 12:01
7
 */
8
9
namespace Bankiru\Api\Rpc\Routing\Annotation;
10
11
/**
12
 * Class Method
13
 *
14
 * Annotation class for @Method().
15
 *
16
 * @Annotation
17
 * @Target({"CLASS", "METHOD"})
18
 */
19
class Method
20
{
21
    public $name;
22
    public $method;
23
    public $context        = [];
24
    public $defaultContext = true;
25
    public $inherit        = true;
26
27 1
    public function __construct(array $values)
28
    {
29 1
        if (array_key_exists('value', $values)) {
30 1
            $values['method'] = $values['value'];
31 1
            unset($values['value']);
32 1
        }
33
34 1
        if (!array_key_exists('method', $values)) {
35
            throw new \RuntimeException('Specify "method" parameter for annotation');
36
        }
37
38 1
        if (!array_key_exists('name', $values)) {
39 1
            $values['name'] = $values['method'];
40 1
        }
41
42 1
        foreach ($values as $k => $v) {
43 1
            if (!method_exists($this, $name = 'set' . $k)) {
44
                throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this)));
45
            }
46
47 1
            $this->$name($v);
48 1
        }
49 1
    }
50
51
    /**
52
     * @return mixed
53
     */
54
    public function getName()
55
    {
56
        return $this->name;
57
    }
58
59
    /**
60
     * @param mixed $name
61
     */
62 1
    public function setName($name)
63
    {
64 1
        $this->name = $name;
65 1
    }
66
67
    /**
68
     * @return mixed
69
     */
70 8
    public function getMethod()
71
    {
72 8
        return $this->method;
73
    }
74
75
    /**
76
     * @param mixed $method
77
     */
78 1
    public function setMethod($method)
79
    {
80 1
        $this->method = $method;
81 1
    }
82
83
    /**
84
     * @return array
85
     */
86 8
    public function getContext()
87
    {
88 8
        return $this->context;
89
    }
90
91
    /**
92
     * @param array $context
93
     */
94 1
    public function setContext($context)
95
    {
96 1
        $this->context = $context;
97 1
    }
98
99
    /**
100
     * @return boolean
101
     */
102 8
    public function isDefaultContext()
103
    {
104 8
        return $this->defaultContext;
105
    }
106
107
    /**
108
     * @param boolean $defaultContext
109
     */
110 1
    public function setDefaultContext($defaultContext)
111
    {
112 1
        $this->defaultContext = $defaultContext;
113 1
    }
114
115
    /**
116
     * @return boolean
117
     */
118 8
    public function isInherit()
119
    {
120 8
        return $this->inherit;
121
    }
122
123
    /**
124
     * @param boolean $inherit
125
     */
126 1
    public function setInherit($inherit)
127
    {
128 1
        $this->inherit = (bool)$inherit;
129 1
    }
130
}
131