SimpleDomainEventStream   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 41
ccs 14
cts 16
cp 0.875
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A hasNext() 0 4 1
A next() 0 8 2
A peek() 0 8 2
A emptyStream() 0 4 1
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