Completed
Push — master ( 3a35ab...03a056 )
by Julián
06:43
created

AbstractAggregateIdentity::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * aggregate (https://github.com/phpgears/aggregate).
5
 * Aggregate base.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/aggregate
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Aggregate;
15
16
use Gears\Immutability\ImmutabilityBehaviour;
17
18
/**
19
 * Base immutable aggregate identity.
20
 */
21
abstract class AbstractAggregateIdentity implements AggregateIdentity
22
{
23
    use ImmutabilityBehaviour;
24
25
    /**
26
     * Identity value.
27
     *
28
     * @var string
29
     */
30
    private $value;
31
32
    /**
33
     * AbstractIdentity constructor.
34
     *
35
     * @param string $value
36
     */
37
    final protected function __construct(string $value)
38
    {
39
        $this->checkImmutability();
40
41
        $this->value = $value;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    final public function isEqualTo($identity): bool
48
    {
49
        return \is_object($identity)
50
            && \get_class($identity) === static::class
51
            && $identity->getValue() === $this->getValue();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    final public function getValue(): string
58
    {
59
        return $this->value;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    final public function __toString(): string
66
    {
67
        return $this->value;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    final public function serialize(): string
74
    {
75
        return \serialize($this->value);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     *
81
     * @param mixed $serialized
82
     */
83
    final public function unserialize($serialized): void
84
    {
85
        $this->value = \unserialize($serialized, [static::class]);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    final public function jsonSerialize(): string
92
    {
93
        return $this->value;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     *
99
     * @return string[]
100
     */
101
    final protected function getAllowedInterfaces(): array
102
    {
103
        return [AggregateIdentity::class];
104
    }
105
}
106