Media::getArtist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace AudioCoreEntity\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
8
use Doctrine\ORM\Mapping\UniqueConstraint;
9
use Symfony\Component\Validator\Constraints as Assert;
10
use Symfony\Component\Serializer\Annotation\Groups;
11
use DeejayPoolBundle\Entity\AvdItem;
12
use DeejayPoolBundle\Entity\SvItem;
13
use DeejayPoolBundle\Entity\FranchisePoolItem;
14
15
/**
16
 * Media
17
 *
18
 * @ORM\Table(
19
 *      indexes={@ORM\Index(name="profider_filename", columns={"fileName"})},
20
 *      uniqueConstraints={@UniqueConstraint(name="full_file_path_md5", columns={"fullFilePathMd5"})},
21
 *      options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}
22
 * )
23
 */
24
class Media
25
{
26
    const MEDIA_TYPE_AUDIO          = 1;
27
    const MEDIA_TYPE_VIDEO          = 2;
28
    /**
29
     * @var string
30
     *
31
     * @ORM\Column(type="string", length=255, nullable=true)
32
     * @Groups({"media-read"})
33
     */
34
    protected $artist;
35
36
    /**
37
     * @var int
38
     *
39
     * @ORM\Column(type="integer", nullable=true)
40
     * @Groups({"media-read"})
41
     */
42
    protected $bpm;
43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(type="text", nullable=true)
47
     * @Groups({"media-read"})
48
     *
49
     */
50
    protected $fullPath;
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(type="string", length=32, nullable=false)
55
     * @Groups({"media-read"})
56
     *
57
     */
58
    protected $fullFilePathMd5;
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(type="string", length=200, nullable=true)
63
     * @Groups({"media-read"})
64
     *
65
     */
66
    protected $dirName;
67
    /**
68
     * @var string
69
     *
70
     * @ORM\Column(type="string", length=255, nullable=true)
71
     * @Groups({"media-read", "artist-read", "genre-read"})
72
     */
73
    protected $title;
74
    /**
75
     * @var \DateTime
76
     *
77
     * @ORM\Column(type="datetime", nullable=true)
78
     * @Groups({"media-read"})
79
     */
80
    protected $releaseDate;
81
    /**
82
     * @var string
83
     *
84
     * @ORM\Column(type="string", length=40, nullable=true)
85
     * @Groups({"media-read"})
86
     */
87
    protected $version;
88
    /**
89
     * @var string
90
     *
91
     * @ORM\Column(type="string", length=255, nullable=true)
92
     * @Groups({"media-read"})
93
     */
94
    protected $fileName;
95
    /**
96
     * @var boolean
97
     *
98
     * @ORM\Column(type="boolean", nullable=false, options={"default":false})
99
     * @Groups({"media-read"})
100
     */
101
    protected $exist = false;
102
    /**
103
     * @var bool
104
     * @todo remove property and associated method
105
     * @ORM\Column(type="boolean", nullable=false, options={"default":false})
106
     * @Groups({"media-read", "genre-read", "artist-read"})
107
     */
108
    protected $tagged = false;
109
    /**
110
     * @var string
111
     *
112
     * @ORM\Column(type="integer", nullable=true)
113
     * @Groups({"media-read"})
114
     */
115
    protected $score = 0;
116
    /**
117
     * @var \DateTime
118
     *
119
     * @ORM\Column(type="datetime", nullable=true)
120
     * @Groups({"media-read"})
121
     */
122
    protected $deletedAt;
123
    /**
124
     * @var integer
125
     *
126
     * @ORM\Column(name="id", type="integer")
127
     * @ORM\Id
128
     * @ORM\GeneratedValue(strategy="AUTO")
129
     */
130
    protected $id;
131
    /**
132
     * @ORM\ManyToMany(targetEntity="\AudioCoreEntity\Entity\Genre", inversedBy="medias", cascade={"persist", "detach", "refresh"}, fetch="EXTRA_LAZY")
133
     * @ORM\JoinTable(name="media_genre",
134
     *      joinColumns={@ORM\JoinColumn(name="media_id", referencedColumnName="id")},
135
     *      inverseJoinColumns={@ORM\JoinColumn(name="genre_id", referencedColumnName="id")}
136
     *      )
137
     * @var ArrayCollection<Genre>
138
     * @Groups({"media-read"})
139
     **/
140
    protected $genres;
141
    /**
142
     * @ORM\ManyToMany(targetEntity="\AudioCoreEntity\Entity\Artist", inversedBy="medias", cascade={"persist", "detach", "refresh"}, fetch="EXTRA_LAZY")
143
     * @ORM\JoinTable(
144
     *      joinColumns={@ORM\JoinColumn(name="media_id", referencedColumnName="id")},
145
     *      inverseJoinColumns={@ORM\JoinColumn(name="artist_id", referencedColumnName="id")}
146
     *      )
147
     * @var ArrayCollection<Artist>
148
     * @Groups({"media-read"})
149
     **/
150
    protected $artists;
151
    /**
152
     * @var integer
153
     *
154
     * @ORM\Column(type="integer", nullable=true)
155
     * @Groups({"media-read"})
156
     */
157
    protected $type;
158
    /**
159
     * @var integer
160
     *
161
     * @ORM\Column(type="integer", length=4, nullable=true)
162
     * @Groups({"media-read", "artist-read", "genre-read"})
163
     */
164
    protected $year;
165
    /**
166
     *
167
     */
168 8
    public function __construct()
169
    {
170 8
        $this->genres = new ArrayCollection();
171 8
        $this->artists = new ArrayCollection();
172 8
    }
173
174 3
    public static function getTypes()
175
    {
176
        return [
177 3
            'audio'         => self::MEDIA_TYPE_AUDIO,
178 3
            'video'         => self::MEDIA_TYPE_VIDEO,
179 3
        ];
180
    }
181
182
    /**
183
     * Get id
184
     *
185
     * @return integer
186
     */
187 1
    public function getId()
188
    {
189 1
        return $this->id;
190
    }
191
192
    /**
193
     * Get artist.
194
     *
195
     * @return string
196
     */
197 1
    public function getArtist()
198
    {
199 1
        return $this->artist;
200
    }
201
202
    /**
203
     * Set artist.
204
     *
205
     * @param string $artist
206
     *
207
     * @return Media
208
     */
209 1
    public function setArtist($artist)
210
    {
211 1
        if ($artist) {
212 1
            $this->artist = substr(trim($artist), 0, 254);
213 1
        }
214
215 1
        return $this;
216
    }
217
218
    /**
219
     * @return int
220
     */
221 2
    public function getBpm()
222
    {
223 2
        return $this->bpm;
224
    }
225
226
    /**
227
     * @param int $bpm
228
     * @return Media
229
     */
230 2
    public function setBpm($bpm)
231
    {
232 2
        if (filter_var($bpm, FILTER_VALIDATE_INT) || filter_var($bpm, FILTER_VALIDATE_FLOAT)) {
233 2
            if ($bpm <= 160 && $bpm >= 60) {
234 2
                $this->bpm = abs($bpm);
0 ignored issues
show
Documentation Bug introduced by
It seems like abs($bpm) can also be of type double. However, the property $bpm is declared as type integer. 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...
235 2
            }
236 2
        }
237 2
        return $this;
238
    }
239
240
    /**
241
     * @return string
242
     */
243 1
    public function getExist()
244
    {
245 1
        return $this->exist;
246
    }
247
248
    /**
249
     * @param string $exist
250
     * @return $this
251
     */
252 1
    public function setExist($exist)
253
    {
254 1
        $this->exist = $exist;
0 ignored issues
show
Documentation Bug introduced by
The property $exist was declared of type boolean, but $exist 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...
255 1
        return $this;
256
    }
257
258
    /**
259
     * Get fullPath.
260
     *
261
     * @return string
262
     */
263 1
    public function getFullPath()
264
    {
265 1
        return $this->fullPath;
266
    }
267
268
    /**
269
     * Set fullPath.
270
     *
271
     * @param string $fullPath
272
     *
273
     * @return Media
274
     */
275 1
    public function setFullPath($fullPath)
276
    {
277 1
        $pattern = '#(' .DIRECTORY_SEPARATOR.')\1+#';
278 1
        $replacement = DIRECTORY_SEPARATOR;
279 1
        $fullPath = preg_replace($pattern, $replacement, $fullPath);
280
281 1
        $this->fullPath = $fullPath;
282
283 1
        $this->exist = file_exists($fullPath) ? true : true;
284 1
        $splFile = new \SplFileInfo($this->fullPath);
285 1
        $this->setFileName($splFile->getBasename());
286 1
        $this->setFullFilePathMd5(md5($this->fullPath));
287 1
        $paths = explode('/', $splFile->getPath());
288 1
        $this->setDirName(end($paths));
289
290 1
        return $this;
291
    }
292
293
    /**
294
     * @return string
295
     */
296 1
    public function getFullFilePathMd5()
297
    {
298 1
        return $this->fullFilePathMd5;
299
    }
300
301
    /**
302
     * @param string $fullFilePathMd5
303
     * @return Media
304
     */
305 1
    public function setFullFilePathMd5($fullFilePathMd5)
306
    {
307 1
        if (strlen($fullFilePathMd5) == 32) {
308 1
            $this->fullFilePathMd5 = $fullFilePathMd5;
309 1
        }
310 1
        return $this;
311
    }
312
313
314
315
    /**
316
     * Get title.
317
     *
318
     * @return string
319
     */
320 1
    public function getTitle()
321
    {
322 1
        return $this->title;
323
    }
324
325
    /**
326
     * Set title.
327
     *
328
     * @param string $title
329
     *
330
     * @return Media
331
     */
332 1
    public function setTitle($title)
333
    {
334 1
        if ($title) {
335 1
            $this->title = trim($title);
336 1
        }
337
338 1
        return $this;
339
    }
340
341
    /**
342
     * Get type
343
     *
344
     * @return integer
345
     */
346 1
    public function getType()
347
    {
348 1
        return $this->type;
349
    }
350
351
    /**
352
     * Set type
353
     *
354
     * @param integer $type
355
     * @return Media
356
     */
357 2
    public function setType($type)
358
    {
359 2
        if (!in_array($type, self::getTypes())) {
360 1
            throw new \InvalidArgumentException(sprintf('%s is not a valid type. See %s', $type, self::class.'::getTypes()'));
361
        }
362
363 1
        $this->type = $type;
364
365 1
        return $this;
366
    }
367
368
    /**
369
     * Get releaseDate.
370
     *
371
     * @return \DateTime
372
     */
373 1
    public function getReleaseDate()
374
    {
375 1
        return $this->releaseDate;
376
    }
377
378
    /**
379
     * Set releaseDate.
380
     *
381
     * @param \DateTime $releaseDate
382
     *
383
     * @return Media
384
     */
385 1
    public function setReleaseDate($releaseDate)
386
    {
387 1
        $this->releaseDate = $releaseDate;
388
389 1
        return $this;
390
    }
391
392
    /**
393
     * @param Genre $genre
394
     * @return $this
395
     */
396 1
    public function addGenre(Genre $genre)
397
    {
398 1
        if (!$this->genres->contains($genre)) {
399 1
            $this->genres->add($genre);
400 1
        }
401 1
        return $this;
402
    }
403
404
    /**
405
     * @param Genre $genre
406
     * @return $this
407
     */
408 1
    public function removeGenre(Genre $genre)
409
    {
410 1
        if ($this->genres->contains($genre)) {
411 1
            $this->genres->removeElement($genre);
412 1
        }
413 1
        return $this;
414
    }
415
416
    /**
417
     * @return ArrayCollection
418
     */
419 1
    public function getGenres()
420
    {
421 1
        return $this->genres;
422
    }
423
424
    /**
425
     * Set Genres.
426
     * @param ArrayCollection $genres
427
     * @return $this
428
     */
429 1
    public function setGenres(ArrayCollection $genres)
430
    {
431 1
        $this->genres = $genres;
432
433 1
        return $this;
434
    }
435
    /**
436
     * @param Artist $artist
437
     * @return $this
438
     */
439 1
    public function addArtist(Artist $artist)
440
    {
441 1
        if (!$this->artists->contains($artist)) {
442 1
            $this->artists->add($artist);
443 1
        }
444 1
        return $this;
445
    }
446
447
    /**
448
     * @param Artist $artist
449
     * @return $this
450
     */
451 1
    public function removeArtist(Artist $artist)
452
    {
453 1
        if ($this->artists->contains($artist)) {
454 1
            $this->artists->removeElement($artist);
455 1
        }
456 1
        return $this;
457
    }
458
459
    /**
460
     * @return ArrayCollection
461
     */
462 1
    public function getArtists()
463
    {
464 1
        return $this->artists;
465
    }
466
467
    /**
468
     * @param ArrayCollection $artists
469
     * @return $this
470
     */
471 1
    public function setArtists(ArrayCollection $artists)
472
    {
473 1
        $this->artists = $artists;
474
475 1
        return $this;
476
    }
477
478
    /**
479
     * Get version.
480
     *
481
     * @return string
482
     */
483 1
    public function getVersion()
484
    {
485 1
        return $this->version;
486
    }
487
488
    /**
489
     * Set version.
490
     *
491
     * @param string $version
492
     *
493
     * @return Media
494
     */
495 1
    public function setVersion($version)
496
    {
497 1
        $this->version = trim($version);
498
499 1
        return $this;
500
    }
501
502
    /**
503
     * @return string
504
     */
505 1
    public function getFileName()
506
    {
507 1
        return $this->fileName;
508
    }
509
510
    /**
511
     * @param string $fileName
512
     * @return $this
513
     */
514 1
    public function setFileName($fileName)
515
    {
516 1
        $this->fileName = $fileName;
517
518 1
        return $this;
519
    }
520
521
    /**
522
     * @return string
523
     */
524 1
    public function getScore()
525
    {
526 1
        return $this->score;
527
    }
528
529
    /**
530
     * @param string $score
531
     * @return Media
532
     */
533 1
    public function setScore($score)
534
    {
535 1
        if (filter_var($score, FILTER_VALIDATE_INT) || filter_var($score, FILTER_VALIDATE_FLOAT)) {
536 1
            $this->score = $score;
537 1
        }
538 1
        return $this;
539
    }
540
541
    /**
542
     * @return \DateTime
543
     */
544 1
    public function getDeletedAt()
545
    {
546 1
        return $this->deletedAt;
547
    }
548
549
    /**
550
     * @param \DateTime $deletedAt
551
     * @return Media
552
     */
553 1
    public function setDeletedAt($deletedAt)
554
    {
555 1
        $this->deletedAt = $deletedAt;
556 1
        return $this;
557
    }
558
559
    /**
560
     * @return string
561
     */
562 1
    public function getDirName()
563
    {
564 1
        return $this->dirName;
565
    }
566
567
    /**
568
     * @param string $dirName
569
     * @return Media
570
     */
571 1
    public function setDirName($dirName)
572
    {
573 1
        $this->dirName = $dirName;
574 1
        return $this;
575
    }
576
    public function isUntaged() {
577
        // @codeCoverageIgnoreStart
578
        return !$this->tagged;
579
        // @codeCoverageIgnoreEnd
580
    }
581
582
    /**
583
     * @return int
584
     */
585 1
    public function getYear()
586
    {
587 1
        return $this->year;
588
    }
589
590
    /**
591
     * @param int $year
592
     * @return Media
593
     */
594 2
    public function setYear($year)
595
    {
596 2
        if (preg_match('/\d{4}/', $year)) {
597 1
            $this->year = $year;
598 1
        }
599 2
        return $this;
600
    }
601
602
    /**
603
     * @return boolean
604
     */
605
    public function getTagged()
606
    {
607
        // @codeCoverageIgnoreStart
608
        return $this->tagged;
609
        // @codeCoverageIgnoreEnd
610
    }
611
612
    /**
613
     * @param bool $tagged
614
     * @return Media
615
     */
616
    public function setTagged($tagged)
617
    {
618
        // @codeCoverageIgnoreStart
619
        $this->tagged = $tagged;
620
        return $this;
621
        // @codeCoverageIgnoreEnd
622
    }
623
624
}
625