Passed
Push — master ( ac27ce...34b8bf )
by Stephen
02:09
created

Duration::getTotalMinutesAttribute()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Sfneal\Helpers\Time\Traits;
5
6
use Sfneal\Helpers\Time\TimeConverter;
7
8
/**
9
 * A time value attributes to an Eloquent Model.
10
 *
11
 * @property $total_duration
12
 * @property $total_seconds
13
 */
14
trait Duration
15
{
16
    /**
17
     * Retrieve the total duration in minutes with decimals.
18
     *
19
     * @return float
20
     */
21
    abstract public function getTotalDurationAttribute();
22
23
    /**
24
     * Retrieve total duration converted to hours.
25
     *
26
     * @return string
27
     */
28
    public function getTotalHoursAttribute()
29
    {
30
        return (new TimeConverter())->setMinutes($this->total_duration)->getHours();
31
    }
32
33
    /**
34
     * Retrieve total duration converted to minutes without decimals.
35
     *
36
     * @return false|float
37
     */
38
    public function getTotalMinutesAttribute()
39
    {
40
        return floor($this->total_duration);
41
    }
42
43
    /**
44
     * Retrieve total duration converted to seconds.
45
     *
46
     * @return float|int
47
     */
48
    public function getTotalSecondsAttribute()
49
    {
50
        return $this->total_duration * 60;
51
    }
52
53
    /**
54
     * Retrieve total seconds converted to 'hours:minutes:seconds' datetime.
55
     *
56
     * @return string
57
     */
58
    public function getTotalTimeAttribute()
59
    {
60
        return (new TimeConverter())->setSeconds($this->total_seconds)->getHours();
61
    }
62
}
63