Completed
Push — master ( d5f261...ed671f )
by Joseph
01:44
created

Quota::getCheckedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
1
<?php
2
3
namespace STS\StorageConnect\Models;
4
5
use Carbon\Carbon;
6
7
/**
8
 * Class Quota
9
 */
10
class Quota
11
{
12
    /**
13
     * @var int
14
     */
15
    protected $total;
16
17
    /**
18
     * @var int
19
     */
20
    protected $used;
21
22
    /**
23
     * @var Carbon
24
     */
25
    protected $checked;
26
27
    /**
28
     * Quota constructor.
29
     *
30
     * @param $total
31
     * @param $used
32
     */
33
    public function __construct( $total, $used )
34
    {
35
        $this->total = $total;
36
        $this->used = $used;
37
        $this->checked = Carbon::now();
38
    }
39
40
    /**
41
     * @return int
42
     */
43
    public function getTotal()
44
    {
45
        return $this->total;
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function getUsed()
52
    {
53
        return $this->used;
54
    }
55
56
    /**
57
     * @return int
58
     */
59
    public function getAvailable()
60
    {
61
        return $this->total - $this->used;
62
    }
63
64
    /**
65
     * @return float|int
66
     */
67
    public function getPercentFull()
68
    {
69
        return $this->total > 0
70
            ? round(($this->used / $this->total) * 100, 1)
71
            : 0;
72
    }
73
74
    /**
75
     * @return Carbon
76
     */
77
    public function getCheckedAt()
78
    {
79
        return $this->checked;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function toArray()
86
    {
87
        return [
88
            'total_space'      => $this->getTotal(),
89
            'space_used'       => $this->getUsed(),
90
            'space_available'  => $this->getAvailable(),
91
            'percent_full'     => $this->getPercentFull(),
92
            'space_checked_at' => $this->getCheckedAt()
93
        ];
94
    }
95
}