Completed
Push — master ( bbff6f...c51acf )
by Rafał
19:14 queued 09:31
created

Item::setName()   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 0
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
    public function __construct()
67
    {
68
        $this->renditions = new ArrayCollection();
69
        $this->items = new ArrayCollection();
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getName(): string
76
    {
77
        return $this->name;
78
    }
79
80
    /**
81
     * @param string $name
82
     */
83
    public function setName(string $name)
84
    {
85
        $this->name = $name;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function getBody()
92
    {
93
        return $this->body;
94
    }
95 4
96
    /**
97 4
     * {@inheritdoc}
98
     */
99
    public function setBody($body)
100
    {
101
        $this->body = $body;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function setRenditions(Collection $renditions)
108
    {
109
        $this->renditions = $renditions;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function getRenditions(): Collection
116
    {
117
        return $this->renditions;
118
    }
119
120
    /**
121
     * @return ArrayCollection
122
     */
123
    public function getItems()
124
    {
125
        return $this->items;
126
    }
127
128
    /**
129
     * @param ArrayCollection $items
130
     */
131
    public function setItems($items)
132
    {
133
        $this->items = $items;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getBodyText()
140
    {
141
        return $this->bodyText;
142
    }
143
144
    /**
145
     * @param string $bodyText
146
     */
147 4
    public function setBodyText($bodyText)
148
    {
149 4
        $this->bodyText = $bodyText;
150 4
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getUsageTerms()
156
    {
157
        return $this->usageTerms;
158
    }
159
160
    /**
161
     * @param string $usageTerms
162
     */
163
    public function setUsageTerms($usageTerms)
164
    {
165
        $this->usageTerms = $usageTerms;
166
    }
167
168
    /**
169
     * Set package.
170
     *
171
     * @param PackageInterface|void $package
172
     *
173
     * @return Item
174
     */
175
    public function setPackage(PackageInterface $package = null)
176
    {
177
        $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...
178
    }
179
180
    /**
181
     * Get package.
182
     *
183
     * @return Package
184
     */
185
    public function getPackage()
186
    {
187
        return $this->package;
188
    }
189
190
    public function setGroup(?GroupInterface $group): void
191
    {
192
        $this->group = $group;
193
    }
194
195
    public function getGroup(): ?GroupInterface
196
    {
197
        return $this->group;
198
    }
199
200
    public function getItemsArray(): array
201
    {
202
        if (null !== $this->items) {
203
            return $this->items->toArray();
204
        }
205
206
        return [];
207
    }
208
209
    public function getGroupsArray(): array
210
    {
211
        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...
212
    }
213
214
    public function getRenditionsArray(): array
215
    {
216
        return $this->renditions->toArray();
217
    }
218
}
219