ParameterBag::setParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the slince/di package.
7
 *
8
 * (c) Slince <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Slince\Di;
15
16
use Dflydev\DotAccessData\Data;
17
18
class ParameterBag extends Data
19
{
20
    /**
21
     * Sets array of parameters.
22
     *
23
     * @param $parameters
24
     */
25
    public function setParameters($parameters)
26
    {
27
        $this->data = $parameters;
28
    }
29
30
    /**
31
     * Adds array of parameters.
32
     *
33
     * @param array $parameters
34
     */
35
    public function addParameters(array $parameters)
36
    {
37
        $this->data = array_replace($this->data, $parameters);
38
    }
39
40
    /**
41
     * Sets parameter with given name and value.
42
     *
43
     * @param int|string $name
44
     * @param mixed      $value
45
     */
46
    public function setParameter($name, $value)
47
    {
48
        $this->data[$name] = $value;
49
    }
50
51
    /**
52
     * Gets the parameter by its name.
53
     *
54
     * @param string $name
55
     * @param mixed  $default
56
     *
57
     * @return mixed
58
     */
59
    public function getParameter($name, $default = null)
60
    {
61
        if (isset($this->data[$name])) {
62
            return $this->data[$name];
63
        }
64
65
        return parent::get($name, $default);
66
    }
67
68
    /**
69
     * Gets all parameters.
70
     *
71
     * @return array
72
     */
73
    public function toArray()
74
    {
75
        return $this->data;
76
    }
77
}
78