GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( ed81f3...cf83d8 )
by Gabriel
05:44
created

AccessMethodsTrait::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace Nip\Collections\Traits;
4
5
/**
6
 * Class AccessMethodsTrait
7
 * @package Nip\Collections\Traits
8
 */
9
trait AccessMethodsTrait
10
{
11
12
13
    /**
14
     * @param array $items
15
     */
16
    public function setItems($items)
17
    {
18
        $this->items = $items;
0 ignored issues
show
Bug introduced by
The property items does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * {@inheritDoc}
23
     */
24 2
    public function add($element, $key = null)
25
    {
26 2
        if ($key == null) {
27 2
            $this->items[] = $element;
28 2
            return;
29
        }
30
        $this->set($key, $element);
31
    }
32
33
    /**
34
     * @param string $id
35
     * @param mixed $value
36
     */
37 3
    public function set($id, $value)
38
    {
39 3
        $this->items[$id] = $value;
40 3
    }
41
42
43
    /**
44
     * Returns a parameter by name.
45
     *
46
     * @param string $key The key
47
     * @param mixed $default The default value if the parameter key does not exist
48
     *
49
     * @return mixed
50
     */
51 1
    public function get($key, $default = null)
52
    {
53 1
        return array_key_exists($key, $this->items) ? $this->items[$key] : $default;
54
    }
55
56
    /**
57
     * @return boolean
58
     * @param string $key
59
     */
60
    public function has($key)
61
    {
62
        return isset($this->items[$key]) || array_key_exists($key, $this->items);
63
    }
64
65
    /**
66
     * @param $key
67
     * @return bool
68
     * @deprecated Use ->has($key) instead
69
     */
70
    public function exists($key)
71
    {
72
        return $this->has($key);
73
    }
74
75
76
    /**
77
     * Returns the parameters.
78
     *
79
     * @return array An array of parameters
80
     */
81 1
    public function all()
82
    {
83 1
        return $this->items;
84
    }
85
86
    /**
87
     * Returns the parameter keys.
88
     *
89
     * @return array An array of parameter keys
90
     */
91
    public function keys()
92
    {
93
        return array_keys($this->items);
94
    }
95
96
    /**
97
     * Returns the parameter values.
98
     *
99
     * @return array An array of parameter values
100
     */
101
    public function values()
102
    {
103
        return array_values($this->items);
104
    }
105
106
107
    /**
108
     * @param string $key
109
     * @return null
110
     */
111 1
    public function unset($key)
112
    {
113 1
        if (!isset($this->items[$key]) && !array_key_exists($key, $this->items)) {
114
            return null;
115
        }
116 1
        $removed = $this->items[$key];
117 1
        unset($this->items[$key]);
118 1
        return $removed;
119
    }
120
}
121