MediaObjectCreated::getLanguage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CultuurNet\UDB3\Media\Events;
4
5
use Broadway\Serializer\SerializableInterface;
6
use CultuurNet\UDB3\Language;
7
use CultuurNet\UDB3\Media\Properties\MIMEType;
8
use ValueObjects\Identity\UUID;
9
use ValueObjects\StringLiteral\StringLiteral;
10
use ValueObjects\Web\Url;
11
12
final class MediaObjectCreated implements SerializableInterface
13
{
14
    /**
15
     * @var UUID
16
     */
17
    protected $mediaObjectId;
18
19
    /**
20
     * @var MIMEType
21
     */
22
    protected $mimeType;
23
24
    /**
25
     * @var String
26
     */
27
    protected $description;
28
29
    /**
30
     * @var String
31
     */
32
    protected $copyrightHolder;
33
34
    /**
35
     * @var Url
36
     */
37
    protected $sourceLocation;
38
39
    /**
40
     * @var Language
41
     */
42
    protected $language;
43
44 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
        UUID $id,
46
        MIMEType $fileType,
47
        StringLiteral $description,
48
        StringLiteral $copyrightHolder,
49
        Url $sourceLocation,
50
        Language $language
51
    ) {
52
        $this->mediaObjectId = $id;
53
        $this->mimeType = $fileType;
54
        $this->description = $description;
0 ignored issues
show
Documentation Bug introduced by
It seems like $description of type object<ValueObjects\StringLiteral\StringLiteral> is incompatible with the declared type string of property $description.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        $this->copyrightHolder = $copyrightHolder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $copyrightHolder of type object<ValueObjects\StringLiteral\StringLiteral> is incompatible with the declared type string of property $copyrightHolder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        $this->sourceLocation = $sourceLocation;
57
        $this->language = $language;
58
    }
59
60
    public function getLanguage(): Language
61
    {
62
        return $this->language;
63
    }
64
65
    public function getMediaObjectId(): UUID
66
    {
67
        return $this->mediaObjectId;
68
    }
69
70
    public function getDescription(): StringLiteral
71
    {
72
        return $this->description;
73
    }
74
75
    public function getCopyrightHolder(): StringLiteral
76
    {
77
        return $this->copyrightHolder;
78
    }
79
80
    public function getMimeType(): MIMEType
81
    {
82
        return $this->mimeType;
83
    }
84
85
    public function getSourceLocation(): Url
86
    {
87
        return $this->sourceLocation;
88
    }
89
90
    public function serialize(): array
91
    {
92
        return array(
93
            'media_object_id' => $this->getMediaObjectId()->toNative(),
94
            'mime_type' => $this->getMimeType()->toNative(),
95
            'description' => $this->getDescription()->toNative(),
96
            'copyright_holder' => $this->getCopyrightHolder()->toNative(),
97
            'source_location' => (string) $this->getSourceLocation(),
98
            'language' => (string) $this->getLanguage(),
99
        );
100
    }
101
102 View Code Duplication
    public static function deserialize(array $data): MediaObjectCreated
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        return new self(
105
            new UUID($data['media_object_id']),
106
            new MIMEType($data['mime_type']),
107
            new StringLiteral($data['description']),
108
            new StringLiteral($data['copyright_holder']),
109
            Url::fromNative($data['source_location']),
110
            array_key_exists('language', $data) ? new Language($data['language']) : new Language('nl')
111
        );
112
    }
113
}
114