Passed
Pull Request — master (#9)
by Pavel
06:21
created

Method::isDefaultContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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