Completed
Push — master ( 1c7520...3a85c6 )
by Rafał
09:11
created

Item::setRenditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Bridge Component.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\Bridge\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use SWP\Component\Common\Model\TimestampableInterface;
20
use SWP\Component\Common\Model\TimestampableTrait;
21
22
class Item extends BaseContent implements ItemInterface, TimestampableInterface
23
{
24
    use TimestampableTrait;
25
26
    /**
27
     * @var string
28
     */
29
    protected $name;
30
31
    /**
32
     * @var string
33
     */
34
    protected $body;
35
36
    /**
37
     * @var string
38
     */
39
    protected $bodyText;
40
41
    /**
42
     * Collection.
43
     */
44
    protected $renditions;
45
46
    /**
47
     * @var string
48
     */
49
    protected $usageTerms;
50
51
    /**
52
     * @var ArrayCollection
53
     */
54
    public $items;
55
56
    /**
57
     * @var Package
58
     */
59
    protected $package;
60
61
    /**
62
     * @var Package
63 4
     */
64
    protected $group;
65 4
66
    /** @var int|null */
67
    protected $position;
68
69
    public function __construct()
70
    {
71
        parent::__construct();
72
        $this->renditions = new ArrayCollection();
73
        $this->items = new ArrayCollection();
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getName(): string
80
    {
81
        return $this->name;
82
    }
83
84
    /**
85
     * @param string $name
86
     */
87
    public function setName(string $name)
88
    {
89
        $this->name = $name;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 4
    public function getBody()
96
    {
97 4
        return $this->body;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function setBody($body)
104
    {
105
        $this->body = $body;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function setRenditions(Collection $renditions)
112
    {
113
        $this->renditions = $renditions;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function getRenditions(): Collection
120
    {
121
        return $this->renditions;
122
    }
123
124
    /**
125
     * @return ArrayCollection
126
     */
127
    public function getItems()
128
    {
129
        return $this->items;
130
    }
131
132
    /**
133
     * @param ArrayCollection $items
134
     */
135
    public function setItems($items)
136
    {
137
        $this->items = $items;
138
    }
139
140
    /**
141
     * @return string
142
     */
143
    public function getBodyText()
144
    {
145
        return $this->bodyText;
146
    }
147 4
148
    /**
149 4
     * @param string $bodyText
150 4
     */
151
    public function setBodyText($bodyText)
152
    {
153
        $this->bodyText = $bodyText;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getUsageTerms()
160
    {
161
        return $this->usageTerms;
162
    }
163
164
    /**
165
     * @param string $usageTerms
166
     */
167
    public function setUsageTerms($usageTerms)
168
    {
169
        $this->usageTerms = $usageTerms;
170
    }
171
172
    /**
173
     * Set package.
174
     *
175
     * @param PackageInterface|void $package
176
     *
177
     * @return Item
178
     */
179
    public function setPackage(PackageInterface $package = null)
180
    {
181
        $this->package = $package;
0 ignored issues
show
Documentation Bug introduced by
It seems like $package can also be of type object<SWP\Component\Bri...Model\PackageInterface>. However, the property $package is declared as type object<SWP\Component\Bridge\Model\Package>. 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...
182
    }
183
184
    /**
185
     * Get package.
186
     *
187
     * @return Package
188
     */
189
    public function getPackage()
190
    {
191
        return $this->package;
192
    }
193
194
    public function setGroup(?GroupInterface $group): void
195
    {
196
        $this->group = $group;
197
    }
198
199
    public function getGroup(): ?GroupInterface
200
    {
201
        return $this->group;
202
    }
203
204
    public function getItemsArray(): array
205
    {
206
        if (null !== $this->items) {
207
            return $this->items->toArray();
208
        }
209
210
        return [];
211
    }
212
213
    public function getGroupsArray(): array
214
    {
215
        return $this->groups->toArray();
0 ignored issues
show
Bug introduced by
The property groups does not seem to exist. Did you mean group?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
216
    }
217
218
    public function getRenditionsArray(): array
219
    {
220
        return $this->renditions->toArray();
221
    }
222
223
    public function getPosition(): ?int
224
    {
225
        return $this->position;
226
    }
227
228
    public function setPosition(?int $position): void
229
    {
230
        $this->position = $position;
231
    }
232
}
233