Passed
Push — 1.11.x ( 80e6f3...6f3dc2 )
by
unknown
14:13
created

PortfolioCategory::setParentId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity;
5
6
use Chamilo\UserBundle\Entity\User;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Criteria;
9
use Doctrine\ORM\Mapping as ORM;
10
11
/**
12
 * Class PortfolioCategory.
13
 *
14
 * @package Chamilo\CoreBundle\Entity
15
 *
16
 * @ORM\Table(
17
 *  name="portfolio_category",
18
 *  indexes={
19
 *      @ORM\Index(name="user", columns={"user_id"})
20
 *  }
21
 * )
22
 * Add @ to the next line if api_get_configuration_value('allow_portfolio_tool') is true
23
 * ORM\Entity()
24
 */
25
class PortfolioCategory
26
{
27
    /**
28
     * @var int
29
     *
30
     * @ORM\Column(name="id", type="integer")
31
     * @ORM\Id
32
     * @ORM\GeneratedValue
33
     */
34
    protected $id;
35
36
    /**
37
     * @var string
38
     *
39
     * @ORM\Column(name="title", type="string", length=255)
40
     */
41
    protected $title;
42
43
    /**
44
     * @var null
45
     *
46
     * @ORM\Column(name="description", type="text", nullable=true)
47
     */
48
    protected $description = null;
49
50
    /**
51
     * @var User
52
     *
53
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User")
54
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
55
     */
56
    protected $user;
57
58
    /**
59
     * @var bool
60
     *
61
     * @ORM\Column(name="is_visible", type="boolean", options={"default": true})
62
     */
63
    protected $isVisible = true;
64
65
    /**
66
     * @var int
67
     *
68
     * @ORM\Column(name="parent_id", type="integer")
69
     */
70
    protected $parentId = 0;
71
72
    /**
73
     * @var \Doctrine\Common\Collections\ArrayCollection
74
     *
75
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Portfolio", mappedBy="category")
76
     */
77
    protected $items;
78
79
    /**
80
     * PortfolioCategory constructor.
81
     */
82
    public function __construct()
83
    {
84
        $this->items = new ArrayCollection();
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92
        return $this->title;
93
    }
94
95
    /**
96
     * Get id.
97
     *
98
     * @return int
99
     */
100
    public function getId()
101
    {
102
        return $this->id;
103
    }
104
105
    /**
106
     * @param int $id
107
     *
108
     * @return PortfolioCategory
109
     */
110
    public function setId($id)
111
    {
112
        $this->id = $id;
113
114
        return $this;
115
    }
116
117
    /**
118
     * Get title.
119
     *
120
     * @return string
121
     */
122
    public function getTitle()
123
    {
124
        return $this->title;
125
    }
126
127
    /**
128
     * Set title.
129
     *
130
     * @param string $title
131
     *
132
     * @return PortfolioCategory
133
     */
134
    public function setTitle($title)
135
    {
136
        $this->title = $title;
137
138
        return $this;
139
    }
140
141
    /**
142
     * Get description.
143
     *
144
     * @return string|null
145
     */
146
    public function getDescription()
147
    {
148
        return $this->description;
149
    }
150
151
    /**
152
     * Set description.
153
     *
154
     * @param string|null $description
155
     *
156
     * @return PortfolioCategory
157
     */
158
    public function setDescription($description)
159
    {
160
        $this->description = $description;
0 ignored issues
show
Documentation Bug introduced by
It seems like $description can also be of type string. However, the property $description is declared as type null. 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...
161
162
        return $this;
163
    }
164
165
    /**
166
     * Get user.
167
     *
168
     * @return User
169
     */
170
    public function getUser()
171
    {
172
        return $this->user;
173
    }
174
175
    /**
176
     * Set user.
177
     *
178
     * @return PortfolioCategory
179
     */
180
    public function setUser(User $user)
181
    {
182
        $this->user = $user;
183
184
        return $this;
185
    }
186
187
    /**
188
     * Get isVisible.
189
     *
190
     * @return bool
191
     */
192
    public function isVisible()
193
    {
194
        return $this->isVisible;
195
    }
196
197
    /**
198
     * Set isVisible.
199
     *
200
     * @param bool $isVisible
201
     *
202
     * @return PortfolioCategory
203
     */
204
    public function setIsVisible($isVisible)
205
    {
206
        $this->isVisible = $isVisible;
207
208
        return $this;
209
    }
210
211
    /**
212
     * @return int
213
     */
214
    public function getParentId()
215
    {
216
        return $this->parentId;
217
    }
218
219
    /**
220
     * Set parent id
221
     *
222
     * @param int $parentId
223
     *
224
     * @return PortfolioCategory
225
     */
226
    public function setParentId(int $parentId)
227
    {
228
        $this->parentId = $parentId;
229
230
        return $this;
231
    }
232
233
234
235
    /**
236
     * Get items.
237
     *
238
     * @param \Chamilo\CoreBundle\Entity\Course|null  $course
239
     * @param \Chamilo\CoreBundle\Entity\Session|null $session
240
     * @param bool                                    $onlyVisibles
241
     *
242
     * @return ArrayCollection
243
     */
244
    public function getItems(Course $course = null, Session $session = null, $onlyVisibles = false)
245
    {
246
        $criteria = Criteria::create();
247
248
        if ($onlyVisibles) {
249
            $criteria->andWhere(
250
                Criteria::expr()->eq('isVisible', true)
251
            );
252
        }
253
254
        if ($course) {
255
            $criteria
256
                ->andWhere(
257
                    Criteria::expr()->eq('course', $course)
258
                )
259
                ->andWhere(
260
                    Criteria::expr()->eq('session', $session)
261
                );
262
        }
263
264
        $criteria->orderBy(['creationDate' => 'DESC']);
265
266
        return $this->items->matching($criteria);
267
    }
268
269
    /**
270
     * Set items.
271
     *
272
     * @return PortfolioCategory
273
     */
274
    public function setItems(ArrayCollection $items)
275
    {
276
        $this->items = $items;
277
278
        return $this;
279
    }
280
}
281