CartCleared::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
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 Ramsey\Uuid\Uuid;
9
use Ramsey\Uuid\UuidInterface;
10
11
/**
12
 * @author Arkadiusz Krakowiak <[email protected]>
13
 */
14
final class CartCleared implements SerializableInterface
15
{
16
    /**
17
     * @var UuidInterface
18
     */
19
    private $cartId;
20
21
    /**
22
     * @param UuidInterface $cartId
23
     */
24
    private function __construct(UuidInterface $cartId)
25
    {
26
        $this->cartId = $cartId;
27
    }
28
29
    /**
30
     * @param UuidInterface $cartId
31
     *
32
     * @return CartCleared
33
     */
34
    public static function occur(UuidInterface $cartId): self
35
    {
36
        return new self($cartId);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public static function deserialize(array $data)
43
    {
44
        return new self(
45
            Uuid::fromString($data['cartId'])
46
        );
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function serialize()
53
    {
54
        return [
55
            'cartId' => $this->cartId->toString()
56
        ];
57
    }
58
}
59