Elasticsearch7StorageResult::getMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/elasticsearch7-adapter project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Elasticsearch7\Storage;
10
11
use Daikon\Metadata\Metadata;
12
use Daikon\Metadata\MetadataInterface;
13
use Daikon\ReadModel\Projection\ProjectionInterface;
14
use Daikon\ReadModel\Projection\ProjectionMap;
15
use Daikon\ReadModel\Storage\StorageResultInterface;
16
17
final class Elasticsearch7StorageResult implements StorageResultInterface
18
{
19
    private ProjectionMap $projectionMap;
20
21
    private MetadataInterface $metadata;
22
23
    public function __construct(ProjectionMap $projectionMap, MetadataInterface $metadata = null)
24
    {
25
        $this->projectionMap = $projectionMap;
26
        $this->metadata = $metadata ?? Metadata::makeEmpty();
27
    }
28
29
    public function getProjectionMap(): ProjectionMap
30
    {
31
        return $this->projectionMap;
32
    }
33
34
    public function getMetadata(): MetadataInterface
35
    {
36
        return $this->metadata;
37
    }
38
39
    public function getFirst(): ?ProjectionInterface
40
    {
41
        if ($this->projectionMap->isEmpty()) {
42
            return null;
43
        }
44
        return $this->projectionMap->first();
45
    }
46
47
    public function getLast(): ?ProjectionInterface
48
    {
49
        if ($this->projectionMap->isEmpty()) {
50
            return null;
51
        }
52
        return $this->projectionMap->last();
53
    }
54
55
    public function isEmpty(): bool
56
    {
57
        return $this->projectionMap->isEmpty();
58
    }
59
60
    public function getIterator(): ProjectionMap
61
    {
62
        return $this->projectionMap;
63
    }
64
65
    public function count(): int
66
    {
67
        return $this->projectionMap->count();
68
    }
69
70
    private function __clone()
71
    {
72
        $this->projectionMap = clone $this->projectionMap;
73
        $this->metadata = clone $this->metadata;
74
    }
75
}
76