Humanresource::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Timegridio\Concierge\Models;
4
5
use Illuminate\Database\Eloquent\Model as EloquentModel;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8
/**
9
 * @property int $id
10
 * @property string $name
11
 * @property int $business_id
12
 * @property Timegridio\Concierge\Models\business $business
13
 * @property int $capacity
14
 * @property string $slug
15
 * @property string $calendar_link
16
 */
17
class Humanresource extends EloquentModel
18
{
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = ['name', 'capacity', 'calendar_link'];
25
26
    protected $guarded = ['id', 'slug'];
27
28
    /**
29
     * Has many human resources.
30
     *
31
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
32
     */
33 1
    public function business()
34
    {
35 1
        return $this->belongsTo(Business::class);
36
    }
37
38
    /**
39
     * Set Calendar link.
40
     *
41
     * @param string $calendar_link
42
     */
43
    public function setCalendarLinkAttribute($calendar_link)
44
    {
45
        return $this->attributes['calendar_link'] = trim($calendar_link) ?: null;
46
    }
47
48
    /**
49
     * TODO: Check slug setting can be moved to a more proper place.
50
     *
51
     * Save the model to the database.
52
     *
53
     * @param array $options
54
     *
55
     * @return bool
56
     */
57 4
    public function save(array $options = [])
58
    {
59 4
        $this->attributes['slug'] = str_slug($this->attributes['name']);
60
61 4
        return parent::save($options);
62
    }
63
}
64