Audience::deserialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Event\ValueObjects;
4
5
use Broadway\Serializer\SerializableInterface;
6
7
final class Audience implements SerializableInterface
8
{
9
    /**
10
     * Store the Audience enum internally as a string to make sure that PHP encode works.
11
     * @var string
12
     */
13
    private $audienceType;
14
15
    /**
16
     * @param AudienceType $audienceType
17
     */
18
    public function __construct(AudienceType $audienceType)
19
    {
20
        $this->audienceType = $audienceType->toNative();
21
    }
22
23
    public function getAudienceType(): AudienceType
24
    {
25
        return AudienceType::fromNative($this->audienceType);
26
    }
27
28
    public static function deserialize(array $data): Audience
29
    {
30
        return new self(
31
            AudienceType::fromNative($data['audienceType'])
32
        );
33
    }
34
35
    public function serialize(): array
36
    {
37
        return [
38
            'audienceType' => $this->getAudienceType()->toNative(),
39
        ];
40
    }
41
42
    public function equals(Audience $otherAudience): bool
43
    {
44
        return $this->getAudienceType() === $otherAudience->getAudienceType();
45
    }
46
}
47