Passed
Push — master ( 7815e3...d45a7a )
by Pieter
04:53
created

ReadModelConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 7
rs 9.4285
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
    public function __construct($name, ReadModelId $id, array $fields, callable $recordFactory, callable $allRecords)
21
    {
22
        $this->name = $name;
23
        $this->id = $id;
24
        $this->fields = $fields;
25
        $this->recordFactory = $recordFactory;
26
        $this->allRecords = $allRecords;
27
    }
28
29
    public function getAllRecords()
30
    {
31
        $allRecords = $this->allRecords;
32
        foreach ($allRecords() as $recordData)
33
            yield $recordData;
34
    }
35
36
    /** @return Record */
37
    public function createRecord($recordData)
38
    {
39
        $recordFactory = $this->recordFactory;
40
        return $recordFactory($recordData);
41
    }
42
}
43