Repo   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B read() 0 34 8
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Utils\Exporter\Sour;
4
5
use FamilyTree365\LaravelGedcom\Models\SourceRepo;
6
use FamilyTree365\LaravelGedcom\Utils\Importer\NoteRef;
7
8
class Repo
9
{
10
    /**
11
     * Gedcom\Record\Sour\Data $data
12
     * String $group
13
     * Integer $group_id.
14
     */
15
    public static function read($conn, \Gedcom\Record\Sour\Repo $data, $group = '', $group_id = 0)
16
    {
17
        $repo_id = $data->getRepo();
18
        if (empty($repo_id)) {
19
            $repo_id = rand(1, 10000);
20
        }
21
        $_caln = $data->getCaln();
22
        $caln = '';
23
        if ($_caln != null && count($_caln) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $_caln can also be of type Gedcom\Record\Sour\Repo; 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

23
        if ($_caln != null && count(/** @scrutinizer ignore-type */ $_caln) > 0) {
Loading history...
24
            $temp = [];
25
            foreach ($_caln as $item) {
26
                $__caln = $item->getCaln();
27
                $__medi = $item->getMedi();
28
                $temp_item = $__caln.':'.$__medi;
29
                $temp[] = $temp_item;
30
            }
31
            $caln = implode(',', $temp);
32
            unset($temp);
33
            // example
34
            // +1 1123 123123:avi,+1 123 123 123:mpg
35
        }
36
        // store Data of sources
37
        $key = ['group'=>$group, 'gid'=>$group_id, 'repo_id'=>$repo_id];
38
        $_data = ['group'=>$group, 'gid'=>$group_id, 'repo_id'=>$repo_id, 'caln'=>$caln];
39
        $record = SourceRepo::on($conn)->updateOrCreate($key, $_data);
40
41
        $_group = 'sourcerepo';
42
        $_gid = $record->id;
43
44
        // \Gedcom\Record\NoteRef array
45
        $note = $data->getNote();
46
        if ($note && count($note) > 0) {
47
            foreach ($note as $item) {
48
                NoteRef::read($conn, $item, $_group, $_gid);
49
            }
50
        }
51
    }
52
}
53