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

ForkCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 9
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 72
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A toArray() 0 9 1
A offsetExists() 0 8 3
A offsetGet() 0 8 2
A offsetSet() 0 4 1
A offsetUnset() 0 4 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