Test Failed
Push — master ( 944b52...dc25eb )
by Taosikai
13:30
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
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);
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...
66
    }
67
68
    /**
69
     * Gets all parameters.
70
     *
71
     * @return array
72
     */
73
    public function toArray()
74
    {
75
        return $this->data;
76
    }
77
}
78