Completed
Push — master ( 20b4d3...f28f70 )
by Julito
09:12 queued 12s
created

ResourceFile::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity\Resource;
5
6
use Chamilo\MediaBundle\Entity\Media;
7
use Doctrine\ORM\Mapping as ORM;
8
use Gedmo\Timestampable\Traits\TimestampableEntity;
9
use Symfony\Component\HttpFoundation\File\File;
10
use Vich\UploaderBundle\Mapping\Annotation as Vich;
11
12
/**
13
 * @ORM\Entity
14
 * @Vich\Uploadable
15
 * @ORM\Table(name="resource_file")
16
 */
17
class ResourceFile
18
{
19
    use TimestampableEntity;
20
21
    /**
22
     * @ORM\Id
23
     * @ORM\Column(type="integer")
24
     * @ORM\GeneratedValue
25
     */
26
    protected $id;
27
28
    /**
29
     * @ORM\OneToOne(targetEntity="Chamilo\MediaBundle\Entity\Media", cascade={"all"})
30
     */
31
    protected $media;
32
33
    /**
34
     * @ORM\Column(type="string", length=255)
35
     *
36
     * @var string
37
     */
38
    protected $name;
39
40
    /**
41
     * @ORM\Column(type="integer")
42
     *
43
     * @var integer
44
     *
45
     */
46
    protected $size;
47
48
    /**
49
     * @Vich\UploadableField(mapping="resources", fileNameProperty="name", size="size")
50
     * @var File
51
     */
52
    protected $file;
53
54
//    /**
55
//     * @var string
56
//     *
57
//     * @Assert\NotBlank()
58
//     *
59
//     * @ORM\Column(name="hash", type="string", nullable=false)
60
//     */
61
//    protected $hash;
62
63
//    /**
64
//     * @Assert\NotBlank()
65
//     *
66
//     * @var string
67
//     *
68
//     * @ORM\Column(name="original_filename", type="string", nullable=false)
69
//     */
70
//    protected $originalFilename;
71
//
72
//    /**
73
//     * @Assert\NotBlank()
74
//     *
75
//     * @var string
76
//     *
77
//     * @ORM\Column(name="size", type="string", nullable=false)
78
//     */
79
//    protected $size;
80
//
81
//    /**
82
//     * @Assert\NotBlank()
83
//     *
84
//     * @var string
85
//     *
86
//     * @ORM\Column(name="width", type="string", nullable=true)
87
//     */
88
//    protected $width;
89
90
//    /**
91
//     * @Assert\NotBlank()
92
//     *
93
//     * @var string
94
//     *
95
//     * @ORM\Column(name="height", type="string", nullable=true)
96
//     */
97
//    protected $height;
98
//
99
//    /**
100
//     * @var string
101
//     *
102
//     * @ORM\Column(name="copyright", type="string", nullable=true)
103
//     */
104
//    protected $copyright;
105
106
//    /**
107
//     * @var string
108
//     *
109
//     * @ORM\Column(name="contentType", type="string", nullable=true)
110
//     */
111
//    protected $contentType;
112
//
113
//    /**
114
//     * @var string
115
//     *
116
//     * @ORM\Column(name="extension", type="string", nullable=false)
117
//     */
118
//    protected $extension;
119
120
    /**
121
     * @var ResourceNode
122
     *
123
     * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="resourceFile")
124
     */
125
    protected $resourceNode;
126
127
    /**
128
     * @var bool
129
     *
130
     * @ORM\Column(name="enabled", type="boolean")
131
     */
132
    //protected $enabled;
133
134
    /**
135
     * Constructor.
136
     */
137
    public function __construct()
138
    {
139
        $this->enabled = true;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
140
        $this->setOriginalFilename(uniqid());
141
    }
142
143
    /**
144
     * @return mixed
145
     */
146
    public function getName()
147
    {
148
        return $this->name;
149
    }
150
151
    /**
152
     * @param mixed $name
153
     *
154
     * @return ResourceFile
155
     */
156
    public function setName($name)
157
    {
158
        $this->name = $name;
159
160
        return $this;
161
    }
162
163
    /**
164
     * @return string
165
     */
166
    public function getHash(): string
167
    {
168
        return $this->hash;
169
    }
170
171
    /**
172
     * @param string $hash
173
     *
174
     * @return ResourceFile
175
     */
176
    public function setHash(string $hash): ResourceFile
177
    {
178
        $this->hash = $hash;
0 ignored issues
show
Bug Best Practice introduced by
The property hash does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
179
180
        return $this;
181
    }
182
183
    /**
184
     * @return string
185
     */
186
    public function getOriginalFilename(): string
187
    {
188
        return $this->originalFilename;
189
    }
190
191
    /**
192
     * @param string $originalFilename
193
     *
194
     * @return ResourceFile
195
     */
196
    public function setOriginalFilename(string $originalFilename): ResourceFile
197
    {
198
        $this->originalFilename = $originalFilename;
0 ignored issues
show
Bug Best Practice introduced by
The property originalFilename does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
199
200
        return $this;
201
    }
202
203
    /**
204
     * @return string
205
     */
206
    public function getSize(): string
207
    {
208
        return $this->size;
209
    }
210
211
    /**
212
     * @param string $size
213
     *
214
     * @return ResourceFile
215
     */
216
    public function setSize(string $size): ResourceFile
217
    {
218
        $this->size = $size;
0 ignored issues
show
Documentation Bug introduced by
The property $size was declared of type integer, but $size is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
219
220
        return $this;
221
    }
222
223
    /**
224
     * @return string
225
     */
226
    public function getWidth(): string
227
    {
228
        return $this->width;
229
    }
230
231
    /**
232
     * @param string $width
233
     *
234
     * @return ResourceFile
235
     */
236
    public function setWidth(string $width): ResourceFile
237
    {
238
        $this->width = $width;
0 ignored issues
show
Bug Best Practice introduced by
The property width does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
239
240
        return $this;
241
    }
242
243
    /**
244
     * @return string
245
     */
246
    public function getHeight(): string
247
    {
248
        return $this->height;
249
    }
250
251
    /**
252
     * @param string $height
253
     *
254
     * @return ResourceFile
255
     */
256
    public function setHeight(string $height): ResourceFile
257
    {
258
        $this->height = $height;
0 ignored issues
show
Bug Best Practice introduced by
The property height does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
259
260
        return $this;
261
    }
262
263
    /**
264
     * @return string
265
     */
266
    public function getCopyright(): string
267
    {
268
        return (string) $this->copyright;
269
    }
270
271
    /**
272
     * @return string
273
     */
274
    public function getContentType(): string
275
    {
276
        return (string) $this->contentType;
277
    }
278
279
    /**
280
     * @param string $contentType
281
     *
282
     * @return ResourceFile
283
     */
284
    public function setContentType(string $contentType): ResourceFile
285
    {
286
        $this->contentType = $contentType;
0 ignored issues
show
Bug Best Practice introduced by
The property contentType does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
287
288
        return $this;
289
    }
290
291
    /**
292
     * @return string
293
     */
294
    public function getExtension(): string
295
    {
296
        return $this->extension;
297
    }
298
299
    /**
300
     * @param string $extension
301
     *
302
     * @return ResourceFile
303
     */
304
    public function setExtension(string $extension): ResourceFile
305
    {
306
        $this->extension = $extension;
0 ignored issues
show
Bug Best Practice introduced by
The property extension does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
307
308
        return $this;
309
    }
310
311
    /**
312
     * @return ResourceNode
313
     */
314
    public function getResourceNode(): ResourceNode
315
    {
316
        return $this->resourceNode;
317
    }
318
319
    /**
320
     * @param ResourceNode $resourceNode
321
     *
322
     * @return ResourceFile
323
     */
324
    public function setResourceNode(ResourceNode $resourceNode): ResourceFile
325
    {
326
        $this->resourceNode = $resourceNode;
327
328
        return $this;
329
    }
330
331
    /**
332
     * @return bool
333
     */
334
    public function isEnabled(): bool
335
    {
336
        return $this->enabled;
337
    }
338
339
    /**
340
     * @param bool $enabled
341
     *
342
     * @return ResourceFile
343
     */
344
    public function setEnabled(bool $enabled): ResourceFile
345
    {
346
        $this->enabled = $enabled;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
347
348
        return $this;
349
    }
350
351
    /**
352
     * @return Media
353
     */
354
    public function getMedia()
355
    {
356
        return $this->media;
357
    }
358
359
    /**
360
     * @param Media $media
361
     *
362
     * @return ResourceFile
363
     */
364
    public function setMedia($media)
365
    {
366
        $this->media = $media;
367
368
        return $this;
369
    }
370
371
    /**
372
     * @return mixed
373
     */
374
    public function getId()
375
    {
376
        return $this->id;
377
    }
378
379
    /**
380
     * @param mixed $id
381
     *
382
     * @return ResourceFile
383
     */
384
    public function setId($id)
385
    {
386
        $this->id = $id;
387
388
        return $this;
389
    }
390
391
    /**
392
     * @return mixed
393
     */
394
    public function getFile(): ?File
395
    {
396
        return $this->file;
397
    }
398
399
    /**
400
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
401
     *
402
     */
403
    public function setFile(File $file = null): void
404
    {
405
        $this->file = $file;
406
407
        if (null !== $file) {
408
            // It is required that at least one field changes if you are using doctrine
409
            // otherwise the event listeners won't be called and the file is lost
410
            $this->updatedAt = new \DateTimeImmutable();
0 ignored issues
show
Bug Best Practice introduced by
The property updatedAt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
411
        }
412
    }
413
}
414