Audience   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
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
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