Completed
Pull Request — master (#261)
by Luc
05:21
created

Audience   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAudienceType() 0 4 1
A deserialize() 0 6 1
A serialize() 0 6 1
A equals() 0 4 1
1
<?php
2
3
namespace CultuurNet\UDB3\Event\ValueObjects;
4
5
use Broadway\Serializer\SerializableInterface;
6
7
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
     * Audience constructor.
17
     * @param AudienceType $audienceType
18
     */
19
    public function __construct(AudienceType $audienceType)
20
    {
21
        $this->audienceType = $audienceType->toNative();
22
    }
23
24
    /**
25
     * @return AudienceType
26
     */
27
    public function getAudienceType()
28
    {
29
        return AudienceType::fromNative($this->audienceType);
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public static function deserialize(array $data)
36
    {
37
        return new static(
38
            AudienceType::fromNative($data['audienceType'])
39
        );
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function serialize()
46
    {
47
        return [
48
            'audienceType' => $this->getAudienceType()->toNative()
49
        ];
50
    }
51
52
    /**
53
     * @param Audience $otherAudience
54
     * @return bool
55
     */
56
    public function equals(Audience $otherAudience)
57
    {
58
        return $this->getAudienceType() === $otherAudience->getAudienceType();
59
    }
60
}
61