WritableEventCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toStreamData() 0 6 1
A validateEvents() 0 8 3
1
<?php
2
namespace EventStore;
3
4
use EventStore\Exception\InvalidWritableEventObjectException;
5
6
/**
7
 * Class WritableEventCollection
8
 * @package EventStore
9
 */
10
final class WritableEventCollection implements WritableToStream
11
{
12
    /**
13
     * @var WritableEvent[]
14
     */
15
    private $events = [];
16
17
    /**
18
     * @param array $events
19
     */
20 24
    public function __construct(array $events)
21
    {
22 24
        $this->validateEvents($events);
23 23
        $this->events = $events;
24 23
    }
25
26
    /**
27
     * @return array
28
     */
29
    public function toStreamData()
30
    {
31 23
        return array_map(function (WritableEvent $event) {
32 23
            return $event->toStreamData();
33 23
        }, $this->events);
34
    }
35
36
    /**
37
     * @param array $events
38
     */
39 24
    private function validateEvents(array $events)
40
    {
41 24
        foreach ($events as $event) {
42 24
            if (!$event instanceof WritableEvent) {
43 24
                throw new InvalidWritableEventObjectException();
44
            }
45
        }
46 23
    }
47
}
48