Passed
Push — develop ( 9324e6...f3eb57 )
by Septianata
04:31
created

Attribute::getRangeOrderBundleAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Models\Concerns\Denomination;
4
5
use Illuminate\Support\Facades\Storage;
6
7
/**
8
 * @property string $name
9
 * @property float $value
10
 * @property \App\Enum\DenominationType $type
11
 * @property int $quantity_per_bundle
12
 * @property int $minimum_order_bundle
13
 * @property int $maximum_order_bundle
14
 * @property string $image
15
 * @property-read array $range_order_bundle
16
 * @property-read float $value_per_bundle
17
 * @property-read float $minimum_order_value
18
 * @property-read float $maximum_order_value
19
 * @property-read string $value_rupiah
20
 *
21
 * @see \App\Models\Denomination
22
 */
23
trait Attribute
24
{
25
    /**
26
     * Return "image" attribute value.
27
     *
28
     * @param  mixed  $value
29
     * @return string|null
30
     */
31 2
    public function getImageAttribute($value): ?string
32
    {
33 2
        if (is_null($value)) {
34 1
            return asset('img/dummy.png');
35
        }
36
37 1
        return Storage::url(static::IMAGE_PATH . '/' . $value);
0 ignored issues
show
Bug introduced by
The constant App\Models\Concerns\Deno...n\Attribute::IMAGE_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
    }
39
40
    /**
41
     * Return "range_order_bundle" attribute value.
42
     *
43
     * @return array
44
     */
45 3
    public function getRangeOrderBundleAttribute(): array
46
    {
47 3
        return range($this->minimum_order_bundle, $this->maximum_order_bundle);
48
    }
49
50
    /**
51
     * Return "value_per_bundle" attribute value.
52
     *
53
     * @return float
54
     */
55
    public function getValuePerBundleAttribute(): float
56
    {
57
        return $this->value * $this->quantity_per_bundle;
58
    }
59
60
    /**
61
     * Return "minimum_order_value" attribute value.
62
     *
63
     * @return float
64
     */
65
    public function getMinimumOrderValueAttribute(): float
66
    {
67
        return $this->value_per_bundle * $this->minimum_order_bundle;
68
    }
69
70
    /**
71
     * Return "maximum_order_value" attribute value.
72
     *
73
     * @return float
74
     */
75
    public function getMaximumOrderValueAttribute(): float
76
    {
77
        return $this->value_per_bundle * $this->maximum_order_bundle;
78
    }
79
80
    /**
81
     * Return "value_rupiah" attribute value.
82
     *
83
     * @return string
84
     */
85
    public function getValueRupiahAttribute(): string
86
    {
87
        return format_rupiah($this->value, 'Rp');
88
    }
89
}
90