SimpleDomainEventStream::emptyStream()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Governor\Framework\Domain;
10
11
/**
12
 * Description of SimpleDomainEventStream
13
 *
14
 * @author david
15
 */
16
class SimpleDomainEventStream implements DomainEventStreamInterface
17
{
18
19
    private $events;
20
    private $nextIndex;
21
22 37
    public function __construct(array $events = array())
23
    {
24 37
        $this->events = $events;
25 37
        $this->nextIndex = 0;
26 37
    }
27
28 38
    public function hasNext()
29
    {
30 38
        return count($this->events) > $this->nextIndex;
31
    }
32
33 37
    public function next()
34
    {
35 37
        if (!$this->hasNext()) {
36 1
            throw new \OutOfBoundsException('Trying to peek beyond the limits of this stream');
37
        }
38
39 37
        return $this->events[$this->nextIndex++];
40
    }
41
42 15
    public function peek()
43
    {
44 15
        if (!$this->hasNext()) {
45 1
            throw new \OutOfBoundsException('Trying to peek beyond the limits of this stream');
46
        }
47
48 14
        return $this->events[$this->nextIndex];
49
    }
50
51
    public static function emptyStream()
52
    {
53
        return new static();
54
    }
55
56
}
57