Completed
Pull Request — master (#103)
by Kristof
11:24 queued 03:48
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\Language;
8
use ValueObjects\String\String;
9
10
final class CollaborationDataAdded implements SerializableInterface
11
{
12
    /**
13
     * @var String
14
     */
15
    protected $eventId;
16
17
    /**
18
     * @var Language
19
     */
20
    protected $language;
21
22
    /**
23
     * @var CollaborationData
24
     */
25
    protected $collaborationData;
26
27
    /**
28
     * @param String $eventId
29
     * @param Language $language
30
     * @param CollaborationData $collaborationData
31
     */
32
    public function __construct(
33
        String $eventId,
34
        Language $language,
35
        CollaborationData $collaborationData
36
    ) {
37
        $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...
38
        $this->language = $language;
39
        $this->collaborationData = $collaborationData;
40
    }
41
42
    /**
43
     * @return String
44
     */
45
    public function getEventId()
46
    {
47
        return $this->eventId;
48
    }
49
50
    /**
51
     * @return Language
52
     */
53
    public function getLanguage()
54
    {
55
        return $this->language;
56
    }
57
58
    /**
59
     * @return CollaborationData
60
     */
61
    public function getCollaborationData()
62
    {
63
        return $this->collaborationData;
64
    }
65
66
    /**
67
     * @param array $data
68
     * @return static The object instance
69
     */
70
    public static function deserialize(array $data)
71
    {
72
        return new static(
73
            new String($data['eventId']),
74
            new Language($data['language']),
75
            CollaborationData::deserialize($data['collaborationData'])
76
        );
77
    }
78
79
    /**
80
     * @return array
81
     */
82
    public function serialize()
83
    {
84
        $serialized = array(
85
            'eventId' => (string) $this->eventId,
86
            'language' => $this->language->getCode(),
87
            'collaborationData' => $this->collaborationData->serialize(),
88
        );
89
90
        return $serialized;
91
    }
92
}
93