Completed
Push — master ( e299e4...94cf65 )
by Taosikai
15:49 queued 02:33
created

ParameterBag   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setParameters() 0 4 1
A addParameters() 0 4 1
A setParameter() 0 4 1
A getParameter() 0 7 2
A toArray() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the slince/di package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slince\Di;
13
14
use Dflydev\DotAccessData\Data;
15
16
class ParameterBag extends Data
17
{
18
    /**
19
     * Sets array of parameters
20
     *
21
     * @param $parameters
22
     */
23
    public function setParameters($parameters)
24
    {
25
        $this->data = $parameters;
26
    }
27
28
    /**
29
     * Adds array of parameters
30
     *
31
     * @param array $parameters
32
     */
33
    public function addParameters(array $parameters)
34
    {
35
        $this->data = array_replace($this->data, $parameters);
36
    }
37
38
    /**
39
     * Sets parameter with given name and value
40
     *
41
     * @param int|string $name
42
     * @param mixed $value
43
     */
44
    public function setParameter($name, $value)
45
    {
46
        $this->data[$name] = $value;
47
    }
48
49
    /**
50
     * Gets the parameter by its name
51
     *
52
     * @param string $name
53
     * @param mixed $default
54
     * @return mixed
55
     */
56
    public function getParameter($name, $default = null)
57
    {
58
        if (isset($this->data[$name])) {
59
            return $this->data[$name];
60
        }
61
        return parent::get($name, $default);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (get() instead of getParameter()). Are you sure this is correct? If so, you might want to change this to $this->get().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
62
    }
63
64
    /**
65
     * Gets all parameters
66
     * @return array
67
     */
68
    public function toArray()
69
    {
70
        return $this->data;
71
    }
72
}
73