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

CollaborationData::deserialize()   D

Complexity

Conditions 9
Paths 128

Size

Total Lines 45
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 45
rs 4.6667
cc 9
eloc 26
nc 128
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3;
4
5
use Broadway\Serializer\SerializableInterface;
6
use ValueObjects\String\String;
7
use ValueObjects\Web\Url;
8
9
class CollaborationData implements SerializableInterface
10
{
11
    /**
12
     * @var String
13
     */
14
    protected $subBrand;
15
16
    /**
17
     * @var String
18
     */
19
    protected $plainText;
20
21
    /**
22
     * @var String
23
     */
24
    protected $title;
25
26
    /**
27
     * @var String
28
     */
29
    protected $text;
30
31
    /**
32
     * @var String
33
     */
34
    protected $copyright;
35
36
    /**
37
     * @var String
38
     */
39
    protected $keyword;
40
41
    /**
42
     * @var String
43
     */
44
    protected $image;
45
46
    /**
47
     * @var String
48
     */
49
    protected $article;
50
51
    /**
52
     * @var Url
53
     */
54
    protected $link;
55
56
    /**
57
     * @param String $subBrand
58
     * @param String $plainText
59
     */
60
    public function __construct(String $subBrand, String $plainText)
61
    {
62
        $this->subBrand = $subBrand;
0 ignored issues
show
Documentation Bug introduced by
It seems like $subBrand can also be of type string. However, the property $subBrand 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...
63
        $this->plainText = $plainText;
0 ignored issues
show
Documentation Bug introduced by
It seems like $plainText can also be of type string. However, the property $plainText 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...
64
    }
65
66
    /**
67
     * @return String|null
68
     */
69
    public function getSubBrand()
70
    {
71
        return $this->subBrand;
72
    }
73
74
    /**
75
     * @return String
76
     */
77
    public function getPlainText()
78
    {
79
        return $this->plainText;
80
    }
81
82
    /**
83
     * @param String $title
84
     * @return static
85
     */
86
    public function withTitle(String $title)
87
    {
88
        $c = clone $this;
89
        $c->title = $title;
0 ignored issues
show
Documentation Bug introduced by
It seems like $title can also be of type string. However, the property $title 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...
90
        return $c;
91
    }
92
93
    /**
94
     * @return String|null
95
     */
96
    public function getTitle()
97
    {
98
        return $this->title;
99
    }
100
101
    /**
102
     * @param String $text
103
     * @return static
104
     */
105
    public function withText(String $text)
106
    {
107
        $c = clone $this;
108
        $c->text = $text;
0 ignored issues
show
Documentation Bug introduced by
It seems like $text can also be of type string. However, the property $text 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...
109
        return $c;
110
    }
111
112
    /**
113
     * @return String|null
114
     */
115
    public function getText()
116
    {
117
        return $this->text;
118
    }
119
120
    /**
121
     * @param String $copyright
122
     * @return static
123
     */
124
    public function withCopyright(String $copyright)
125
    {
126
        $c = clone $this;
127
        $c->copyright = $copyright;
0 ignored issues
show
Documentation Bug introduced by
It seems like $copyright can also be of type string. However, the property $copyright 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...
128
        return $c;
129
    }
130
131
    /**
132
     * @return String|null
133
     */
134
    public function getCopyright()
135
    {
136
        return $this->copyright;
137
    }
138
139
    /**
140
     * @param String $keyword
141
     * @return static
142
     */
143
    public function withKeyword(String $keyword)
144
    {
145
        $c = clone $this;
146
        $c->keyword = $keyword;
0 ignored issues
show
Documentation Bug introduced by
It seems like $keyword can also be of type string. However, the property $keyword 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...
147
        return $c;
148
    }
149
150
    /**
151
     * @return String|null
152
     */
153
    public function getKeyword()
154
    {
155
        return $this->keyword;
156
    }
157
158
    /**
159
     * @param String $article
160
     * @return static
161
     */
162
    public function withArticle(String $article)
163
    {
164
        $c = clone $this;
165
        $c->article = $article;
0 ignored issues
show
Documentation Bug introduced by
It seems like $article can also be of type string. However, the property $article 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...
166
        return $c;
167
    }
168
169
    /**
170
     * @return String|null
171
     */
172
    public function getArticle()
173
    {
174
        return $this->article;
175
    }
176
177
    /**
178
     * @param String $image
179
     * @return static
180
     */
181
    public function withImage(String $image)
182
    {
183
        $c = clone $this;
184
        $c->image = $image;
0 ignored issues
show
Documentation Bug introduced by
It seems like $image can also be of type string. However, the property $image 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...
185
        return $c;
186
    }
187
188
    /**
189
     * @return String
190
     */
191
    public function getImage()
192
    {
193
        return $this->image;
194
    }
195
196
    /**
197
     * @param Url $link
198
     * @return static
199
     */
200
    public function withLink(Url $link)
201
    {
202
        $c = clone $this;
203
        $c->link = $link;
204
        return $c;
205
    }
206
207
    /**
208
     * @return Url
209
     */
210
    public function getLink()
211
    {
212
        return $this->link;
213
    }
214
215
    /**
216
     * @param array $data
217
     * @return static
218
     */
219
    public static function deserialize(array $data)
220
    {
221
        /* @var CollaborationData $collaboration */
222
        $collaboration = new static(
223
            new String($data['subBrand']),
224
            new String(isset($data['plainText']) ? $data['plainText'] : '')
225
        );
226
227
        if (isset($data['title'])) {
228
            $collaboration = $collaboration
229
                ->withTitle(new String($data['title']));
230
        }
231
232
        if (isset($data['text'])) {
233
            $collaboration = $collaboration
234
                ->withText(new String($data['text']));
235
        }
236
237
        if (isset($data['copyright'])) {
238
            $collaboration = $collaboration
239
                ->withCopyright(new String($data['copyright']));
240
        }
241
242
        if (isset($data['keyword'])) {
243
            $collaboration = $collaboration
244
                ->withKeyword(new String($data['keyword']));
245
        }
246
247
        if (isset($data['image'])) {
248
            $collaboration = $collaboration
249
                ->withImage(new String($data['image']));
250
        }
251
252
        if (isset($data['article'])) {
253
            $collaboration = $collaboration
254
                ->withArticle(new String($data['article']));
255
        }
256
257
        if (isset($data['link'])) {
258
            $collaboration = $collaboration
259
                ->withLink(Url::fromNative($data['link']));
260
        }
261
262
        return $collaboration;
263
    }
264
265
    /**
266
     * @return array
267
     */
268
    public function serialize()
269
    {
270
        $data = [
271
            'subBrand' => (string) $this->subBrand,
272
            'plainText' => (string) $this->plainText,
273
            'title' => (string) $this->title,
274
            'text' => (string) $this->text,
275
            'copyright' => (string) $this->copyright,
276
            'keyword' => (string) $this->keyword,
277
            'image' => (string) $this->image,
278
            'article' => (string) $this->article,
279
            'link' => (string) $this->link,
280
        ];
281
282
        return array_filter($data, 'strlen');
283
    }
284
}
285