Completed
Pull Request — develop (#27)
by Chris
01:52
created

ArrayAccessor::isChanged()   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 0
1
<?php
2
3
namespace Chrisyue\PhpM3u8\DataAccessor;
4
5
class ArrayAccessor implements DataAccessorInterface
6
{
7
    private $data;
8
9
    private $changed;
10
11
    private $initData;
12
13
    public function __construct(array $initData = [])
14
    {
15
        $this->initData = $initData;
16
        $this->data = $this->initData;
17
    }
18
19
    public function add($key, $value)
20
    {
21
        $this->changed = true;
22
        $this->data[$key][] = $value;
23
    }
24
25
    public function set($key, $value)
26
    {
27
        $this->changed = true;
28
        $this->data[$key] = $value;
29
    }
30
31
    public function get($key)
32
    {
33
        if (isset($this->data[$key])) {
34
            return $this->data[$key];
35
        }
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function getData()
42
    {
43
        return $this->data;
44
    }
45
46
    public function isChanged()
47
    {
48
        return $this->changed;
49
    }
50
51
    public function reset()
52
    {
53
        $this->data = $this->initData;
54
        $this->isChanged = false;
0 ignored issues
show
Bug introduced by
The property isChanged does not seem to exist. Did you mean changed?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
55
    }
56
}
57