Passed
Push — master ( 6758f1...14e78e )
by Curtis
05:20
created

Person::birth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Person extends LaravelEnso\People\app\Person
0 ignored issues
show
Bug introduced by
The type App\LaravelEnso\People\app\Person 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...
9
{
10
    use SoftDeletes;
11
12
    /**
13
     * The attributes that should be mutated to dates.
14
     *
15
     * @var array
16
     */
17
    protected $dates = ['deleted_at', 'birthday'];
18
19
    protected $fillable = [
20
        'givn',
21
        'surn',
22
        'sex',
23
        'child_in_family_id',
24
        'description',
25
        'title', 'name', 'appellative', 'uid', 'email', 'phone', 'birthday',
26
        'bank', 'bank_account', 'obs',
27
28
    ];
29
30
    public function events()
31
    {
32
        return $this->hasMany(PersonEvent::class);
33
    }
34
35
    public function child_in_family()
36
    {
37
        return $this->belongsTo(Family::class, 'child_in_family_id');
38
    }
39
40
    public function husband_in_family()
41
    {
42
        return $this->hasMany(Family::class, 'husband_id');
43
    }
44
45
    public function wife_in_family()
46
    {
47
        return $this->hasMany(Family::class, 'wife_id');
48
    }
49
50
    public function fullname()
51
    {
52
        return $this->givn . " " . $this->surn;
53
    }
54
55
    public function getSex()
56
    {
57
        if ($this->sex == "F") {
58
            return "Female";
59
        }
60
61
        return "Male";
62
    }
63
64
    public static function getList()
65
    {
66
        $persons = self::get();
67
        $result = array();
68
        foreach ($persons as $person) {
69
            $result[$person->id] = $person->fullname();
70
        }
71
72
        return collect($result);
73
    }
74
75
    public function addEvent($title, $date, $place, $description = '')
76
    {
77
        $place_id = Place::getIdByTitle($place);
78
        $event = PersonEvent::create(array(
79
            'person_id' => $this->id,
80
            'title' => $title,
81
            'description' => $description,
82
        ));
83
84
        if ($date) {
85
            $event->date = $date;
0 ignored issues
show
Bug introduced by
The property date does not exist on App\PersonEvent. Did you mean dates?
Loading history...
86
            $event->save();
87
        }
88
89
        if ($place) {
90
            $event->places_id = $place_id;
0 ignored issues
show
Bug introduced by
The property places_id does not seem to exist on App\PersonEvent. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
91
            $event->save();
92
        }
93
    }
94
95
    public function birth()
96
    {
97
        return $this->events->where('title', '=', 'BIRT')->first();
98
    }
99
100
    public function death()
101
    {
102
        return $this->events->where('title', '=', 'DEAT')->first();
103
    }
104
}
105