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

ArrayAccessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A add() 0 5 1
A set() 0 5 1
A get() 0 6 2
A getData() 0 4 1
A isChanged() 0 4 1
A reset() 0 5 1
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