StreamId   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
A startsWith() 0 4 1
A isSystem() 0 4 1
A isMetadata() 0 4 1
A toString() 0 4 1
1
<?php
2
3
namespace RayRutjes\GetEventStore;
4
5
class StreamId
6
{
7
    const ALL = '$all';
8
9
    /**
10
     * @var string
11
     */
12
    private $value;
13
14
    /**
15
     * @var bool
16
     */
17
    private $isSystem = false;
18
19
    /**
20
     * @var bool
21
     */
22
    private $isMetadata = false;
23
24
    /**
25
     * EventStream constructor.
26
     *
27
     * @param string $value
28
     */
29
    public function __construct(string $value = '')
30
    {
31
        // todo: add some additional alphanum + $ check.
32
33
        if (empty($value)) {
34
            $value = self::ALL;
35
        }
36
37
        if ($this->startsWith($value, '$$')) {
38
            $this->isMetadata = true;
39
        } elseif ($this->startsWith($value, '$')) {
40
            $this->isSystem = true;
41
        }
42
        $this->value = $value;
43
    }
44
45
    /**
46
     * @param $value
47
     * @param $prefix
48
     *
49
     * @return bool
50
     */
51
    private function startsWith(string $value, string $prefix): bool
52
    {
53
        return strrpos($value, $prefix, -strlen($value)) !== false;
54
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function isSystem(): bool
60
    {
61
        return $this->isSystem;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function isMetadata(): bool
68
    {
69
        return $this->isMetadata;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function toString(): string
76
    {
77
        return $this->value;
78
    }
79
}
80