Duration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 4
b 0
f 0
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTotalSecondsAttribute() 0 3 1
A getTotalHoursAttribute() 0 3 1
A getTotalTimeAttribute() 0 3 1
A getTotalMinutesAttribute() 0 3 1
1
<?php
2
3
namespace Sfneal\Helpers\Time\Traits;
4
5
use Sfneal\Helpers\Time\TimeConverter;
6
7
/**
8
 * A time value attributes to an Eloquent Model.
9
 *
10
 * @property $total_duration
11
 * @property $total_hours
12
 * @property $total_minutes
13
 * @property $total_seconds
14
 * @property $total_time
15
 */
16
trait Duration
17
{
18
    /**
19
     * Retrieve the total duration in minutes with decimals.
20
     *
21
     * // todo: refactor to protected method for overriding & default functionality
22
     *
23
     * @return float
24
     */
25
    abstract public function getTotalDurationAttribute(): float;
26
27
    /**
28
     * Retrieve total duration converted to hours.
29
     *
30
     * @return string
31
     */
32
    public function getTotalHoursAttribute(): string
33
    {
34
        return (new TimeConverter())->setMinutes($this->total_duration)->getHours();
35
    }
36
37
    /**
38
     * Retrieve total duration converted to minutes without decimals.
39
     *
40
     * // todo: fix return type to integer
41
     *
42
     * @return false|float
43
     */
44
    public function getTotalMinutesAttribute()
45
    {
46
        return floor($this->total_duration);
47
    }
48
49
    /**
50
     * Retrieve total duration converted to seconds.
51
     *
52
     * todo: fix return type to integer
53
     *
54
     * @return float|int
55
     */
56
    public function getTotalSecondsAttribute()
57
    {
58
        return $this->total_duration * 60;
59
    }
60
61
    /**
62
     * Retrieve total seconds converted to 'hours:minutes:seconds' datetime.
63
     *
64
     * @return string
65
     */
66
    public function getTotalTimeAttribute(): string
67
    {
68
        return (new TimeConverter())->setSeconds($this->total_seconds)->getHours(true);
69
    }
70
}
71