Completed
Push — v4.0 ( 989be1...ff495d )
by Masiukevich
02:21
created

IndexKey::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * Event Sourcing implementation.
5
 *
6
 * @author  Maksim Masiukevich <[email protected]>
7
 * @license MIT
8
 * @license https://opensource.org/licenses/MIT
9
 */
10
11
declare(strict_types = 1);
12
13
namespace ServiceBus\EventSourcing\Indexes;
14
15
use ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty;
16
use ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty;
17
18
/**
19
 * The key for the value stored in the index.
20
 *
21
 * @psalm-readonly
22
 */
23
final class IndexKey
24
{
25
    public string $indexName;
26
27
    public string $valueKey;
28
29
    /**
30
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty
31
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty
32
     */
33 4
    public function __construct(string $indexName, string $valueKey)
34
    {
35 4
        self::assertIndexNameIsNotEmpty($indexName);
36 4
        self::assertValueKeyIsNotEmpty($valueKey);
37
38 4
        $this->indexName = $indexName;
39 4
        $this->valueKey  = $valueKey;
40 4
    }
41
42
    /**
43
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty
44
     */
45 4
    private static function assertIndexNameIsNotEmpty(string $indexName): void
46
    {
47 4
        if ('' === $indexName)
48
        {
49
            throw new IndexNameCantBeEmpty('Index name can\'t be empty');
50
        }
51 4
    }
52
53
    /**
54
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty
55
     */
56 4
    private static function assertValueKeyIsNotEmpty(string $valueKey): void
57
    {
58 4
        if ('' === $valueKey)
59
        {
60
            throw new ValueKeyCantBeEmpty('Value key can\'t be empty');
61
        }
62 4
    }
63
}
64