Completed
Push — master ( 351c32...271583 )
by Taosikai
19:55 queued 04:54
created

ParameterBag.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
     *
55
     * @return mixed
56
     */
57
    public function getParameter($name, $default = null)
58
    {
59
        if (isset($this->data[$name])) {
60
            return $this->data[$name];
61
        }
62
63
        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...
64
    }
65
66
    /**
67
     * Gets all parameters.
68
     *
69
     * @return array
70
     */
71
    public function toArray()
72
    {
73
        return $this->data;
74
    }
75
}
76