1 | <?php |
||
16 | final class StreamRevision implements ValueObjectInterface |
||
17 | { |
||
18 | private const INITIAL = 1; |
||
19 | |||
20 | private const NONE = 0; |
||
21 | |||
22 | /** @var int */ |
||
23 | private $revision; |
||
24 | |||
25 | 1 | public static function fromNative($revision): ValueObjectInterface |
|
29 | |||
30 | public static function makeEmpty(): ValueObjectInterface |
||
34 | |||
35 | 1 | public function toNative(): int |
|
39 | |||
40 | public function increment(): StreamRevision |
||
41 | { |
||
42 | $copy = clone $this; |
||
43 | $copy->revision++; |
||
44 | return $copy; |
||
45 | } |
||
46 | |||
47 | public function decrement(): StreamRevision |
||
53 | |||
54 | public function equals(ValueObjectInterface $otherValue): bool |
||
59 | |||
60 | public function isEmpty(): bool |
||
64 | |||
65 | public function isInitial(): bool |
||
69 | |||
70 | public function isWithinRange(StreamRevision $from, StreamRevision $to) |
||
71 | { |
||
72 | return $this->isGreaterThanOrEqual($from) && $this->isLessThanOrEqual($to); |
||
73 | } |
||
74 | |||
75 | public function isGreaterThanOrEqual(StreamRevision $revision) |
||
76 | { |
||
77 | return $this->revision >= $revision->toNative(); |
||
78 | } |
||
79 | |||
80 | public function isLessThanOrEqual(StreamRevision $revision) |
||
81 | { |
||
82 | return $this->revision <= $revision->toNative(); |
||
83 | } |
||
84 | |||
85 | public function __toString(): string |
||
89 | |||
90 | 1 | private function __construct(int $revision) |
|
94 | } |
||
95 |