Completed
Push — master ( dc82d8...d048aa )
by Kristof
14:05
created

ImageUpdateTrait::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $description can also be of type string. However, the property $description is declared as type object<ValueObjects\String\String>. Maybe add an additional type check?

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 $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. 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.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
50
        $this->copyrightHolder = $copyrightHolder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $copyrightHolder can also be of type string. However, the property $copyrightHolder is declared as type object<ValueObjects\String\String>. Maybe add an additional type check?

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 $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. 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.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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