|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Offer; |
|
4
|
|
|
|
|
5
|
|
|
use ValueObjects\Identity\UUID; |
|
6
|
|
|
use ValueObjects\String\String; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Trait for image update commands and events. |
|
10
|
|
|
*/ |
|
11
|
|
|
trait ImageUpdateTrait |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The id of the item that has its image updated. |
|
15
|
|
|
* @var int |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $itemId; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The id of the media object that the new information applies to. |
|
21
|
|
|
* @var UUID |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $mediaObjectId; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \ValueObjects\String\String |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \ValueObjects\String\String |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $copyrightHolder; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param $itemId |
|
37
|
|
|
* @param UUID $mediaObjectId |
|
38
|
|
|
* @param \ValueObjects\String\String $description |
|
39
|
|
|
* @param \ValueObjects\String\String $copyrightHolder |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
$itemId, |
|
43
|
|
|
UUID $mediaObjectId, |
|
44
|
|
|
String $description, |
|
45
|
|
|
String $copyrightHolder |
|
46
|
|
|
) { |
|
47
|
|
|
$this->itemId = $itemId; |
|
48
|
|
|
$this->mediaObjectId = $mediaObjectId; |
|
49
|
|
|
$this->description = $description; |
|
|
|
|
|
|
50
|
|
|
$this->copyrightHolder = $copyrightHolder; |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return int |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getItemId() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->itemId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return UUID |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getMediaObjectId() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->mediaObjectId; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return String |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getDescription() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->description; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return String |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getCopyrightHolder() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->copyrightHolder; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
|
|
public function serialize() |
|
89
|
|
|
{ |
|
90
|
|
|
return array( |
|
91
|
|
|
'item_id' => $this->itemId, |
|
92
|
|
|
'media_object_id' => (string) $this->mediaObjectId, |
|
93
|
|
|
'description' => (string) $this->description, |
|
94
|
|
|
'copyright_holder' => (string) $this->copyrightHolder |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param array $data |
|
100
|
|
|
* @return static |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function deserialize(array $data) |
|
103
|
|
|
{ |
|
104
|
|
|
return new static( |
|
105
|
|
|
$data['item_id'], |
|
106
|
|
|
new UUID($data['media_object_id']), |
|
107
|
|
|
new String($data['description']), |
|
108
|
|
|
new String($data['copyright_holder']) |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.