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

Attribute   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 9
c 1
b 0
f 0
dl 0
loc 65
ccs 6
cts 14
cp 0.4286
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRangeOrderBundleAttribute() 0 3 1
A getMaximumOrderValueAttribute() 0 3 1
A getMinimumOrderValueAttribute() 0 3 1
A getValuePerBundleAttribute() 0 3 1
A getImageAttribute() 0 7 2
A getValueRupiahAttribute() 0 3 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