Completed
Push — master ( 6eeebe...30a536 )
by Zoltán
16:45
created

AbstractArrayObject::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace BuildR\Foundation\Object;
2
3
use BuildR\Foundation\Object\ArrayObjectInterface;
4
use \ArrayIterator;
5
6
/**
7
 * Common interface for object that can be convertible to array.
8
 *
9
 * BuildR PHP Framework
10
 *
11
 * @author Zoltán Borsos <[email protected]>
12
 * @package Foundation
13
 * @subpackage Object
14
 *
15
 * @copyright    Copyright 2015, Zoltán Borsos.
16
 * @license      https://github.com/Zolli/BuildR/blob/master/LICENSE.md
17
 * @link         https://github.com/Zolli/BuildR
18
 */
19
class AbstractArrayObject implements ArrayObjectInterface {
20
21
    /**
22
     * @type array
23
     */
24
    protected $data = [];
25
26
    /**
27
     * @inheritDoc
28
     */
29 1
    public function toArray() {
30 1
        return $this->data;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36 2
    public function count() {
37 2
        return (int) count($this->data);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 1
    public function getIterator() {
44 1
        return new ArrayIterator($this->data);
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50 2
    public function offsetExists($offset) {
51 2
        return (bool) isset($this->data[$offset]);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57 2
    public function offsetGet($offset) {
58 2
        return isset($this->data[$offset]) ? $this->data[$offset] : NULL;
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64 1
    public function offsetSet($offset, $value) {
65 1
        $this->data[$offset] = $value;
66 1
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 2
    public function offsetUnset($offset) {
72 2
        if(isset($this->data[$offset])) {
73 2
            unset($this->data[$offset]);
74 2
        }
75 2
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80 1
    public function serialize() {
81 1
        return serialize($this->data);
82
    }
83
84
    /**
85
     * @inheritDoc
86
     */
87 1
    public function unserialize($serialized) {
88 1
        $this->data = unserialize($serialized);
89 1
    }
90
91
}
92