Passed
Pull Request — master (#9)
by Pavel
12:36
created

Method::getOptions()   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
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
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
    public $options        = [];
21
22 1
    public function __construct(array $values)
23
    {
24 1
        if (array_key_exists('value', $values)) {
25 1
            $values['method'] = $values['value'];
26 1
            unset($values['value']);
27 1
        }
28
29 1
        if (!array_key_exists('method', $values)) {
30
            throw new \RuntimeException('Specify "method" parameter for annotation');
31
        }
32
33 1
        if (!array_key_exists('name', $values)) {
34 1
            $values['name'] = $values['method'];
35 1
        }
36
37 1
        foreach ($values as $k => $v) {
38 1
            if (!method_exists($this, $name = 'set' . $k)) {
39
                throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this)));
40
            }
41
42 1
            $this->$name($v);
43 1
        }
44 1
    }
45
46
    /**
47
     * @return mixed
48
     */
49
    public function getName()
50
    {
51
        return $this->name;
52
    }
53
54
    /**
55
     * @param mixed $name
56
     */
57 1
    public function setName($name)
58
    {
59 1
        $this->name = $name;
60 1
    }
61
62
    /**
63
     * @return mixed
64
     */
65 2
    public function getMethod()
66
    {
67 2
        return $this->method;
68
    }
69
70
    /**
71
     * @param mixed $method
72
     */
73 1
    public function setMethod($method)
74
    {
75 1
        $this->method = $method;
76 1
    }
77
78
    /**
79
     * @return array
80
     */
81 2
    public function getContext()
82
    {
83 2
        return $this->context;
84
    }
85
86
    /**
87
     * @param array $context
88
     */
89 1
    public function setContext($context)
90
    {
91 1
        $this->context = $context;
92 1
    }
93
94
    /**
95
     * @return boolean
96
     */
97 2
    public function isDefaultContext()
98
    {
99 2
        return $this->defaultContext;
100
    }
101
102
    /**
103
     * @param boolean $defaultContext
104
     */
105 1
    public function setDefaultContext($defaultContext)
106
    {
107 1
        $this->defaultContext = $defaultContext;
108 1
    }
109
110
    /**
111
     * @return boolean
112
     */
113 2
    public function isInherit()
114
    {
115 2
        return $this->inherit;
116
    }
117
118
    /**
119
     * @param boolean $inherit
120
     */
121 1
    public function setInherit($inherit)
122
    {
123 1
        $this->inherit = (bool)$inherit;
124 1
    }
125
126
    /**
127
     * @return array
128
     */
129 2
    public function getOptions()
130
    {
131 2
        return $this->options;
132
    }
133
134
    /**
135
     * @param array $options
136
     */
137
    public function setOptions(array $options = null)
138
    {
139
        $this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options can be null. However, the property $options is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
140
    }
141
}
142