Completed
Pull Request — master (#311)
by
unknown
04:10
created

MediaObjectCreated::getLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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
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
    /**
45
     * MediaObjectCreated constructor.
46
     * @param UUID $id
47
     * @param MIMEType $fileType
48
     * @param \ValueObjects\StringLiteral\StringLiteral $description
49
     * @param \ValueObjects\StringLiteral\StringLiteral $copyrightHolder
50
     * @param Language $language
51
     * @param Url $sourceLocation
52
     */
53 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...
54
        UUID $id,
55
        MIMEType $fileType,
56
        StringLiteral $description,
57
        StringLiteral $copyrightHolder,
58
        Url $sourceLocation,
59
        Language $language
60
    ) {
61
        $this->mediaObjectId = $id;
62
        $this->mimeType = $fileType;
63
        $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...
64
        $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...
65
        $this->sourceLocation = $sourceLocation;
66
        $this->language = $language;
67
    }
68
69
    /**
70
     * @return Language
71
     */
72
    public function getLanguage()
73
    {
74
        return $this->language;
75
    }
76
77
    /**
78
     * @return UUID
79
     */
80
    public function getMediaObjectId()
81
    {
82
        return $this->mediaObjectId;
83
    }
84
85
    /**
86
     * @return StringLiteral
87
     */
88
    public function getDescription()
89
    {
90
        return $this->description;
91
    }
92
93
    /**
94
     * @return StringLiteral
95
     */
96
    public function getCopyrightHolder()
97
    {
98
        return $this->copyrightHolder;
99
    }
100
101
    /**
102
     * @return MIMEType
103
     */
104
    public function getMimeType()
105
    {
106
        return $this->mimeType;
107
    }
108
109
    /**
110
     * @return Url
111
     */
112
    public function getSourceLocation()
113
    {
114
        return $this->sourceLocation;
115
    }
116
117
    /**
118
     * @return array
119
     */
120
    public function serialize()
121
    {
122
        return array(
123
            'media_object_id' => $this->getMediaObjectId()->toNative(),
124
            'mime_type' => $this->getMimeType()->toNative(),
125
            'description' => $this->getDescription()->toNative(),
0 ignored issues
show
Bug introduced by
The method toNative cannot be called on $this->getDescription() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
126
            'copyright_holder' => $this->getCopyrightHolder()->toNative(),
0 ignored issues
show
Bug introduced by
The method toNative cannot be called on $this->getCopyrightHolder() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
127
            'source_location' => (string) $this->getSourceLocation(),
128
            'language' => (string) $this->getLanguage()
129
        );
130
    }
131
132
    /**
133
     * @param array $data
134
     *
135
     * @return MediaObjectCreated The object instance
136
     */
137 View Code Duplication
    public static function deserialize(array $data)
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...
138
    {
139
        return new static(
140
            new UUID($data['media_object_id']),
141
            new MIMEType($data['mime_type']),
142
            new StringLiteral($data['description']),
143
            new StringLiteral($data['copyright_holder']),
144
            Url::fromNative($data['source_location']),
145
            array_key_exists('language', $data) ? new Language($data['language']) : new Language('nl')
146
        );
147
    }
148
}
149