Completed
Pull Request — master (#7)
by Harry
01:43
created

ImmutableContainer::removeParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/*
3
 * This file is part of Graze DataStructure
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/data-structure/blob/master/LICENSE
11
 * @link http://github.com/graze/data-structure
12
 */
13
14
namespace Graze\DataStructure\Container;
15
16
class ImmutableContainer extends Container
17
{
18
    /**
19
     * @param array $params
20
     */
21
    public function __construct(array $params = [])
22
    {
23
        parent::__construct([]);
24
25
        foreach ($params as $key => $value) {
26
            $this->setParameter($key, $value);
27
        }
28
    }
29
30
    /**
31
     * @param string $key
32
     * @param mixed  $value
33
     *
34
     * @return ContainerInterface
35
     */
36
    public function set($key, $value)
37
    {
38
        $cont = clone $this;
39
        $cont->setParameter($key, $value);
40
41
        return $cont;
42
    }
43
44
    /**
45
     * @param string $key
46
     *
47
     * @return ContainerInterface
48
     */
49
    public function remove($key)
50
    {
51
        if ($this->has($key)) {
52
            $cont = clone $this;
53
            $cont->removeParameter($key);
54
55
            return $cont;
56
        }
57
58
        return $this;
59
    }
60
61
    /**
62
     * @param string $key
63
     * @param mixed  $value
64
     *
65
     * @return ContainerInterface
66
     */
67
    protected function setParameter($key, $value)
68
    {
69
        return parent::set($key, $value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (set() instead of setParameter()). Are you sure this is correct? If so, you might want to change this to $this->set().

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...
70
    }
71
72
    /**
73
     * @param string $key
74
     *
75
     * @return ContainerInterface
76
     */
77
    protected function removeParameter($key)
78
    {
79
        return parent::remove($key);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (remove() instead of removeParameter()). Are you sure this is correct? If so, you might want to change this to $this->remove().

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...
80
    }
81
}
82