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

CollaborationData::withCopyright()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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