Test Failed
Push — develop ( d3d02f...9481b3 )
by Brent
04:21
created

ThreadHandlerCollection::offsetSet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Pageon\Pcntl;
4
5
use ArrayAccess;
6
use InvalidArgumentException;
7
use Iterator;
8
9
class ThreadHandlerCollection implements Iterator, ArrayAccess
10
{
11
    private $position;
12
13
    private $array = [];
14
15
    public function __construct() {
16
        $this->position = 0;
17
    }
18
19
    public function current() {
20
        return $this->array[$this->position];
21
    }
22
23
    public function next() {
24
        ++$this->position;
25
    }
26
27
    public function key() {
28
        return $this->position;
29
    }
30
31
    public function valid() {
32
        return isset($this->array[$this->position]);
33
    }
34
35
    public function rewind() {
36
        $this->position = 0;
37
    }
38
39
    public function offsetExists($offset) {
40
        return isset($this->array[$offset]);
41
    }
42
43
    public function offsetGet($offset) {
44
        return isset($this->array[$offset]) ? $this->array[$offset] : null;
45
    }
46
47
    public function offsetSet($offset, $value) {
48
        if (!$value instanceof ThreadHandler) {
49
            throw new InvalidArgumentException("value must be instance of ThreadHandler.");
50
        }
51
52
        if (is_null($offset)) {
53
            $this->array[] = $value;
54
        } else {
55
            $this->array[$offset] = $value;
56
        }
57
    }
58
59
    public function offsetUnset($offset) {
60
        unset($this->array[$offset]);
61
    }
62
}
63