Record::getDeductableHours()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Chriscreates\Projects\Models;
4
5
use Chriscreates\Projects\Collections\RecordsCollection;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphTo;
8
9
class Record extends Model
10
{
11
    protected $table = 'records';
12
13
    public $primaryKey = 'id';
14
15
    public $guarded = ['id'];
16
17
    public $timestamps = true;
18
19
    protected $dates = [
20
        'time_from',
21
        'time_to',
22
    ];
23
24
    public function recordable() : MorphTo
25
    {
26
        return $this->morphTo();
27
    }
28
29
    public function getDeductableHours()
30
    {
31
        if ( ! $this->deductable && ! $this->deduct_hours) {
32
            return 0;
33
        }
34
35
        return $this->deduct_hours;
36
    }
37
38
    public function getRecordableHours()
39
    {
40
        if ($this->add_hours && ! $this->deductable) {
41
            return $this->add_hours;
42
        }
43
44
        if ( ! $this->time_from || ! $this->time_to) {
45
            return 0;
46
        }
47
48
        return $this->time_from->floatDiffInRealHours($this->time_to, false);
49
    }
50
51
    /**
52
     * Create a new Eloquent Collection instance.
53
     *
54
     * @param  array  $models
55
     * @return \Illuminate\Database\Eloquent\Collection
56
     */
57
    public function newCollection(array $models = [])
58
    {
59
        return new RecordsCollection($models);
60
    }
61
}
62