Passed
Push — v4.2 ( 50993c )
by Masiukevich
07:39
created

IndexKey   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 40
ccs 11
cts 13
cp 0.8462
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertValueKeyIsNotEmpty() 0 5 2
A assertIndexNameIsNotEmpty() 0 5 2
A __construct() 0 7 1
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-immutable
22
 */
23
final class IndexKey
24
{
25
    /** @var string  */
26
    public $indexName;
27
28
    /** @var string  */
29
    public $valueKey;
30
31
    /**
32
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty
33
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty
34
     */
35 4
    public function __construct(string $indexName, string $valueKey)
36
    {
37 4
        self::assertIndexNameIsNotEmpty($indexName);
38 4
        self::assertValueKeyIsNotEmpty($valueKey);
39
40 4
        $this->indexName = $indexName;
41 4
        $this->valueKey  = $valueKey;
42 4
    }
43
44
    /**
45
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty
46
     */
47 4
    private static function assertIndexNameIsNotEmpty(string $indexName): void
48
    {
49 4
        if ('' === $indexName)
50
        {
51
            throw new IndexNameCantBeEmpty('Index name can\'t be empty');
52
        }
53 4
    }
54
55
    /**
56
     * @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty
57
     */
58 4
    private static function assertValueKeyIsNotEmpty(string $valueKey): void
59
    {
60 4
        if ('' === $valueKey)
61
        {
62
            throw new ValueKeyCantBeEmpty('Value key can\'t be empty');
63
        }
64 4
    }
65
}
66