ParameterBag   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 105
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 4 1
A keys() 0 4 1
A add() 0 6 1
A set() 0 6 1
A get() 0 4 2
A has() 0 4 1
A remove() 0 6 1
A getIterator() 0 4 1
A count() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the tmilos/jose-jwt package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\JoseJwt\Util;
13
14
class ParameterBag implements \IteratorAggregate, \Countable
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $parameters;
20
21
    /**
22
     * @param array $parameters
23
     */
24
    public function __construct(array $parameters = array())
25
    {
26
        $this->parameters = $parameters;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function all()
33
    {
34
        return $this->parameters;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function keys()
41
    {
42
        return array_keys($this->parameters);
43
    }
44
45
    /**
46
     * @param array $parameters
47
     *
48
     * @return ParameterBag
49
     */
50
    public function add(array $parameters = array())
51
    {
52
        $this->parameters = array_replace($this->parameters, $parameters);
53
54
        return $this;
55
    }
56
57
    /**
58
     * @param string $key
59
     * @param mixed  $value
60
     *
61
     * @return ParameterBag
62
     */
63
    public function set($key, $value)
64
    {
65
        $this->parameters[$key] = $value;
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param string $key
72
     * @param mixed  $default
73
     *
74
     * @return mixed
75
     */
76
    public function get($key, $default = null)
77
    {
78
        return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
79
    }
80
81
    /**
82
     * @param string $key
83
     *
84
     * @return bool
85
     */
86
    public function has($key)
87
    {
88
        return array_key_exists($key, $this->parameters);
89
    }
90
91
    /**
92
     * @param string $key
93
     *
94
     * @return ParameterBag
95
     */
96
    public function remove($key)
97
    {
98
        unset($this->parameters[$key]);
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return \ArrayIterator
105
     */
106
    public function getIterator()
107
    {
108
        return new \ArrayIterator($this->parameters);
109
    }
110
111
    /**
112
     * @return int
113
     */
114
    public function count()
115
    {
116
        return count($this->parameters);
117
    }
118
}
119