Completed
Pull Request — master (#103)
by Kristof
08:54
created

CollaborationDataAdded::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
rs 9.6667
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace CultuurNet\UDB3\Event\Events;
4
5
use Broadway\Serializer\SerializableInterface;
6
use CultuurNet\UDB3\CollaborationData;
7
use CultuurNet\UDB3\CollaborationData\CollaborationDataPropertiesTrait;
8
use CultuurNet\UDB3\Language;
9
use CultuurNet\UDB3\CollaborationData\Description;
10
use CultuurNet\UDB3\Link\LinkType;
11
use ValueObjects\String\String;
12
use ValueObjects\Web\Url;
13
14
final class CollaborationDataAdded implements SerializableInterface
15
{
16
    /**
17
     * @var String
18
     */
19
    protected $eventId;
20
21
    /**
22
     * @var Language
23
     */
24
    protected $language;
25
26
    /**
27
     * @var CollaborationData
28
     */
29
    protected $collaborationData;
30
31
    /**
32
     * @param String $eventId
33
     * @param Language $language
34
     * @param CollaborationData $collaborationData
35
     */
36
    public function __construct(
37
        String $eventId,
38
        Language $language,
39
        CollaborationData $collaborationData
40
    ) {
41
        $this->eventId = $eventId;
0 ignored issues
show
Documentation Bug introduced by
It seems like $eventId can also be of type string. However, the property $eventId 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...
42
        $this->language = $language;
43
        $this->collaborationData = $collaborationData;
44
    }
45
46
    /**
47
     * @return String
48
     */
49
    public function getEventId()
50
    {
51
        return $this->eventId;
52
    }
53
54
    /**
55
     * @return Language
56
     */
57
    public function getLanguage()
58
    {
59
        return $this->language;
60
    }
61
62
    /**
63
     * @return CollaborationData
64
     */
65
    public function getCollaborationData()
66
    {
67
        return $this->collaborationData;
68
    }
69
70
    /**
71
     * @param array $data
72
     * @return static The object instance
73
     */
74
    public static function deserialize(array $data)
75
    {
76
        return new static(
77
            new String($data['eventId']),
78
            new Language($data['language']),
79
            CollaborationData::deserialize($data['collaborationData'])
80
        );
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    public function serialize()
87
    {
88
        $serialized = array(
89
            'eventId' => (string) $this->eventId,
90
            'language' => $this->language->getCode(),
91
            'collaborationData' => $this->collaborationData->serialize(),
92
        );
93
94
        return $serialized;
95
    }
96
}
97