Passed
Push — develop ( 6302a9...3db2fb )
by Septianata
04:45
created

Attribute::getImageAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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 float $value_per_bundle
16
 * @property-read float $minimum_order_value
17
 * @property-read float $maximum_order_value
18
 * @property-read string $value_rupiah
19
 *
20
 * @see \App\Models\Denomination
21
 */
22
trait Attribute
23
{
24
    /**
25
     * Return "image" attribute value.
26
     *
27
     * @param  mixed  $value
28
     * @return string|null
29
     */
30 2
    public function getImageAttribute($value): ?string
31
    {
32 2
        if (is_null($value)) {
33 1
            return asset('img/dummy.png');
34
        }
35
36 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...
37
    }
38
39
    /**
40
     * Return "value_per_bundle" attribute value.
41
     *
42
     * @return float
43
     */
44
    public function getValuePerBundleAttribute(): float
45
    {
46
        return $this->value * $this->quantity_per_bundle;
47
    }
48
49
    /**
50
     * Return "minimum_order_value" attribute value.
51
     *
52
     * @return float
53
     */
54
    public function getMinimumOrderValueAttribute(): float
55
    {
56
        return $this->value_per_bundle * $this->minimum_order_bundle;
57
    }
58
59
    /**
60
     * Return "maximum_order_value" attribute value.
61
     *
62
     * @return float
63
     */
64
    public function getMaximumOrderValueAttribute(): float
65
    {
66
        return $this->value_per_bundle * $this->maximum_order_bundle;
67
    }
68
69
    /**
70
     * Return "value_rupiah" attribute value.
71
     *
72
     * @return string
73
     */
74
    public function getValueRupiahAttribute(): string
75
    {
76
        return format_rupiah($this->value, 'Rp');
77
    }
78
}
79