ObjeRef   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B read() 0 30 7
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Exporter;
4
5
use FamilyTree365\LaravelGedcom\Models\MediaObject;
6
use FamilyTree365\LaravelGedcom\Utils\Importer\ObjeRef\File;
7
8
class ObjeRef
9
{
10
    /**
11
     * \Gedcom\Record\ObjeRef $objeref
12
     * String $group
13
     * Integer $group_id.
14
     */
15
    public static function read($conn, \Gedcom\Record\ObjeRef $objeref, $group = '', $group_id = 0, $obje_ids = [])
16
    {
17
        if ($objeref == null) {
18
            return;
19
        }
20
        $obje_id = $objeref->getObje();
21
        if (isset($obje_ids[$obje_id])) {
22
            $obje_id = $obje_ids[$obje_id];
23
        }
24
        $titl = $objeref->getTitl();
25
        $file = $objeref->getFile();
0 ignored issues
show
Unused Code introduced by
The assignment to $file is dead and can be removed.
Loading history...
26
27
        // store MediaObject
28
        $key = ['group'=>$group, 'gid'=>$group_id, 'titl'=>$titl];
29
        $data = [
30
            'group'  => $group,
31
            'gid'    => $group_id,
32
            'obje_id'=> $obje_id,
33
            'titl'   => $titl,
34
        ];
35
        $record = MediaObject::on($conn)->updateOrCreate($key, $data);
36
37
        $_group = 'objeref';
38
        $_gid = $record->id;
39
        // store Note
40
41
        $files = $objeref->getFile();
42
        if ($files && count((is_countable($files) ? $files : []))) {
0 ignored issues
show
Bug introduced by
It seems like is_countable($files) ? $files : array() can also be of type Gedcom\Record\ObjeRef; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        if ($files && count(/** @scrutinizer ignore-type */ (is_countable($files) ? $files : []))) {
Loading history...
43
            foreach ($files as $item) {
44
                File::read($conn, $item, $_group, $_gid);
45
            }
46
        }
47
    }
48
}
49