CartInitialized::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace SyliusCart\Domain\Event;
6
7
use Broadway\Serializer\SerializableInterface;
8
use Money\Currency;
9
use Ramsey\Uuid\Uuid;
10
use Ramsey\Uuid\UuidInterface;
11
12
/**
13
 * @author Arkadiusz Krakowiak <[email protected]>
14
 */
15
final class CartInitialized implements SerializableInterface
16
{
17
    /**
18
     * @var UuidInterface
19
     */
20
    private $cartId;
21
22
    /**
23
     * @var Currency
24
     */
25
    private $cartCurrency;
26
27
    /**
28
     * @param UuidInterface $cartId
29
     * @param Currency $cartCurrency
30
     */
31
    private function __construct(UuidInterface $cartId, Currency $cartCurrency)
32
    {
33
        $this->cartId = $cartId;
34
        $this->cartCurrency = $cartCurrency;
35
    }
36
37
    /**
38
     * @param UuidInterface $cartId
39
     * @param Currency $cartCurrency
40
     *
41
     * @return self
42
     */
43
    public static function occur(UuidInterface $cartId, Currency $cartCurrency): self
44
    {
45
        return new self($cartId, $cartCurrency);
46
    }
47
48
    /**
49
     * @return UuidInterface
50
     */
51
    public function getCartId(): UuidInterface
52
    {
53
        return $this->cartId;
54
    }
55
56
    /**
57
     * @return Currency
58
     */
59
    public function getCartCurrency(): Currency
60
    {
61
        return $this->cartCurrency;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public static function deserialize(array $data)
68
    {
69
        return new self(
70
            Uuid::fromString($data['cartId']),
71
            new Currency($data['cartCurrency'])
72
        );
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function serialize()
79
    {
80
        return [
81
            'cartId' => $this->cartId->toString(),
82
            'cartCurrency' => $this->cartCurrency->jsonSerialize()
83
        ];
84
    }
85
}
86