Completed
Push — master ( 65c93a...df2332 )
by Akihito
02:29
created

ForkCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
namespace Ackintosh\Snidel;
3
4
class ForkCollection implements \ArrayAccess
5
{
6
    /** @var \Ackintosh\Snidel\Fork[] */
7
    private $forks = array();
8
9
    /**
10
     * @param   \Ackintosh\Snidel\Fork[]
11
     */
12
    public function __construct($forks)
13
    {
14
        array_map(function ($fork) {
15
            $this->forks[] = $fork;
16
        }, $forks);
17
    }
18
19
    /**
20
     * @return  array
21
     */
22
    public function toArray()
23
    {
24
        return array_map(
25
            function ($fork) {
26
                return $fork->getResult()->getReturn();
27
            },
28
            $this->forks
29
        );
30
    }
31
32
    /**
33
     * @param   mixed   $offset
34
     * @return  bool
35
     */
36
    public function offsetExists($offset)
37
    {
38
        if (isset($this->forks[$offset]) && $this->forks[$offset] !== '') {
39
            return true;
40
        }
41
42
        return false;
43
    }
44
45
    /**
46
     * @param   mixed   $offset
47
     * @return  mixed
48
     */
49
    public function offsetGet($offset)
50
    {
51
        if (!$this->offsetExists($offset)) {
52
            return null;
53
        }
54
55
        return $this->forks[$offset];
56
    }
57
58
    /**
59
     * @param   mixed   $offset
60
     * @return  void
61
     */
62
    public function offsetSet($offset, $value)
63
    {
64
        $this->forks[$offset] = $value;
65
    }
66
67
    /**
68
     * @param   mixed   $offset
69
     * @return  void
70
     */
71
    public function offsetUnset($offset)
72
    {
73
        unset($this->forks[$offset]);
74
    }
75
}
76