Issues (533)

src/Models/Family.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace FamilyTree365\LaravelGedcom\Models;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
The type Illuminate\Database\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class Family extends Model
8
{
9
    protected $fillable = ['description', 'is_active', 'type_id', 'husband_id', 'wife_id', 'chan', 'nchi', 'rin'];
10
11
    protected $attributes = ['is_active' => false];
12
13
    protected $casts = ['is_active' => 'boolean'];
14
15
    public function events()
16
    {
17
        return $this->hasMany(FamilyEvent::class);
18
    }
19
20
    public function children()
21
    {
22
        return $this->hasMany(Person::class, 'child_in_family_id');
23
    }
24
25
    public function husband()
26
    {
27
        return $this->hasOne(Person::class, 'id', 'husband_id');
28
    }
29
30
    public function wife()
31
    {
32
        return $this->hasOne(Person::class, 'id', 'wife_id');
33
    }
34
35
    public function title()
36
    {
37
        return ($this->husband ? $this->husband->fullname() : '?').
38
            ' + '.
39
            ($this->wife ? $this->wife->fullname() : '?');
40
    }
41
42
    public static function getList()
43
    {
44
        $families = self::query()->get();
45
        $result = [];
46
        foreach ($families as $family) {
47
            $result[$family->id] = $family->title();
48
        }
49
50
        return collect($result);
0 ignored issues
show
The function collect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

50
        return /** @scrutinizer ignore-call */ collect($result);
Loading history...
51
    }
52
53
    public function addEvent($title, $date, $place, $description = '')
54
    {
55
        $place_id = Place::getIdByTitle($place);
56
        $event = FamilyEvent::query()->updateOrCreate(
57
            [
58
                'family_id' => $this->id,
59
                'title'     => $title,
60
            ],
61
            [
62
                'family_id'   => $this->id,
63
                'title'       => $title,
64
                'description' => $description,
65
            ]
66
        );
67
        if ($date) {
68
            $event->date = $date;
69
            $event->save();
70
        }
71
        if ($place) {
72
            $event->places_id = $place_id;
73
            $event->save();
74
        }
75
    }
76
77
    public function getWifeName()
78
    {
79
        return $this->wife ? $this->wife->fullname() : 'unknown woman';
80
    }
81
82
    public function getHusbandName()
83
    {
84
        return $this->husband ? $this->husband->fullname() : 'unknown man';
85
    }
86
}
87