Completed
Pull Request — develop (#27)
by Chris
02:25
created

ObjectAccessor::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Chrisyue\PhpM3u8\DataAccessor;
4
5
class ObjectAccessor implements DataAccessorInterface
6
{
7
    private $initData;
8
9
    private $data;
10
11
    private $changed;
12
13
    /**
14
     * @param object $initData
15
     */
16
    public function __construct($initData)
17
    {
18
        $this->initData = $initData;
19
        $this->data = clone $this->initData;
20
    }
21
22
    public function add($key, $value)
23
    {
24
        $this->data->$key[] = $value;
25
        $this->changed = true;
26
    }
27
28
    public function set($key, $value)
29
    {
30
        $this->data->$key = $value;
31
        $this->changed = true;
32
    }
33
34
    public function get($key)
35
    {
36
        return $this->data->$key;
37
    }
38
39
    /**
40
     * @return object
41
     */
42
    public function getData()
43
    {
44
        return $this->data;
45
    }
46
47
    public function isChanged()
48
    {
49
        return $this->changed;
50
    }
51
52
    public function reset()
53
    {
54
        $this->data = clone $this->initData;
55
        $this->changed = false;
56
    }
57
}
58