Passed
Push — master ( 4f5b3b...1c5d75 )
by Darko
09:48
created

MediaInfo   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B addData() 0 25 7
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
use Mhor\MediaInfo\Container\MediaInfoContainer;
8
9
class MediaInfo extends Model
10
{
11
    use HasFactory;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Database\Eloquent\Factories\HasFactory requires the property $factoryClass which is not provided by App\Models\MediaInfo.
Loading history...
12
13
    protected $guarded = [];
14
15
    public static function addData($id, MediaInfoContainer $xmlArray): void
16
    {
17
        $mediainfoArray = $xmlArray->getGeneral();
18
        if (! $mediainfoArray) {
19
            return;
20
        }
21
22
        // Check if we have the same release in the database
23
        if (self::where('releases_id', $id)->exists()) {
24
            return;
25
        }
26
27
        $mediaUniqueId = $mediainfoArray->get('unique_id');
28
        // If unique_id is not present or is 0 or 0x0, we don't want to store it, as it's not unique
29
        if ($mediaUniqueId === null || $mediaUniqueId === '0' || $mediaUniqueId === '0x0' || $mediaUniqueId === 0) {
30
            $mediaUniqueId = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $mediaUniqueId is dead and can be removed.
Loading history...
31
        }
32
33
        self::insertOrIgnore([
34
            'releases_id' => $id,
35
            'movie_name' => $mediainfoArray->get('movie_name') ?? null,
36
            'file_name' => $mediainfoArray->get('file_name') ?? null,
37
            'unique_id' => $mediainfoArray->get('unique_id') ?? null,
38
            'created_at' => now(),
39
            'updated_at' => now(),
40
        ]);
41
    }
42
}
43