Completed
Pull Request — master (#23)
by Florian
07:59
created

AbstractChain::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Cocur\Chain;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use IteratorAggregate;
8
use JsonSerializable;
9
10
/**
11
 * Chain.
12
 *
13
 * @author    Florian Eckerstorfer
14
 * @copyright 2015 Florian Eckerstorfer
15
 */
16
abstract class AbstractChain implements ArrayAccess, IteratorAggregate, JsonSerializable
17
{
18
    /**
19
     * @var array
20
     */
21
    public $array = [];
22
23
    /**
24
     * @return ArrayIterator
25
     */
26 1
    public function getIterator()
27
    {
28 1
        return new ArrayIterator($this->array);
29
    }
30
31
    /**
32
     * @param mixed $offset
33
     *
34
     * @return bool
35
     */
36 1
    public function offsetExists($offset)
37
    {
38 1
        return isset($this->array[$offset]);
39
    }
40
41
    /**
42
     * @param mixed $offset
43
     *
44
     * @return mixed
45
     */
46 1
    public function offsetGet($offset)
47
    {
48 1
        return $this->array[$offset];
49
    }
50
51
    /**
52
     * @param mixed $offset
53
     * @param mixed $value
54
     */
55 1
    public function offsetSet($offset, $value)
56
    {
57 1
        $this->array[$offset] = $value;
58 1
    }
59
60
    /**
61
     * @param mixed $offset
62
     */
63 1
    public function offsetUnset($offset)
64
    {
65 1
        unset($this->array[$offset]);
66 1
    }
67
68
    /**
69
     * @return array
70
     */
71 1
    public function jsonSerialize()
72
    {
73 1
        return $this->array;
74
    }
75
}
76