Passed
Push — master ( d17173...2c21ba )
by Pieter
05:43
created

ReadModelConfiguration::getSnapshotColumnName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Avoran\Rapido\ReadModel;
4
5
final class ReadModelConfiguration
6
{
7
    private $name;
8
    public function getName() { return $this->name; }
9
10
    private $id;
11
    public function getId() { return $this->id; }
12
13
    /** @var ReadModelField[] */
14
    private $fields;
15
    public function getFields() { return $this->fields; }
16
17
    private $recordFactory;
18
    private $allRecords;
19
20
    private $snapshotColumnName;
21
    public function generateSnapshot() { return $this->snapshotColumnName !== null; }
22
    public function getSnapshotColumnName() { return $this->snapshotColumnName; }
23
24
    public function __construct
25
    (
26
        $name,
27
        ReadModelId $id,
28
        array $fields,
29
        callable $recordFactory,
30
        callable $allRecords,
31
        $snapshotColumnName = null
32
    )
33
    {
34
        $this->name = $name;
35
        $this->id = $id;
36
        $this->fields = $fields;
37
        $this->recordFactory = $recordFactory;
38
        $this->allRecords = $allRecords;
39
        $this->snapshotColumnName = $snapshotColumnName;
40
    }
41
42
    public function getAllRecords()
43
    {
44
        $allRecords = $this->allRecords;
45
        foreach ($allRecords() as $recordData)
46
            yield $recordData;
47
    }
48
49
    /** @return Record */
50
    public function createRecord($recordData)
51
    {
52
        $recordFactory = $this->recordFactory;
53
        return $recordFactory($recordData);
54
    }
55
}
56