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

ImmutableFlatContainer::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/*
3
 * This file is part of Graze DataStructure
4
 *
5
 * Copyright (c) 2017 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 ImmutableFlatContainer extends FlatContainer
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->doSet($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->doSet($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->doRemove($key);
54
55
            return $cont;
56
        }
57
58
        return $this;
59
    }
60
}
61