Passed
Push — develop ( 37402c...c02995 )
by Septianata
07:07
created

Attribute::getMaximumOrderQuantityAttribute()   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 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
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 $code
9
 * @property string $name
10
 * @property float $value
11
 * @property \App\Enum\DenominationType $type
12
 * @property int $quantity_per_bundle
13
 * @property int $minimum_order_bundle
14
 * @property int $maximum_order_bundle
15
 * @property int $minimum_order_quantity
16
 * @property int $maximum_order_quantity
17
 * @property bool $can_order_custom_quantity
18
 * @property bool $is_visible
19
 * @property string $image
20
 * @property-read array $range_order_bundle
21
 * @property-read float $value_per_bundle
22
 * @property-read float $minimum_order_value
23
 * @property-read float $maximum_order_value
24
 * @property-read string $value_rupiah
25
 * @property-read string $type_badge
26
 * @property-read string $can_order_custom_quantity_badge
27
 * @property-read string $is_visible_badge
28
 *
29
 * @see \App\Models\Denomination
30
 */
31
trait Attribute
32
{
33
    /**
34
     * Return "minimum_order_quantity" attribute value.
35
     *
36
     * @param  mixed  $value
37
     * @return int
38
     */
39 2
    public function getMinimumOrderQuantityAttribute($value): int
40
    {
41 2
        if ($this->can_order_custom_quantity) {
42 1
            return $this->castAttribute('minimum_order_quantity', $value);
0 ignored issues
show
Bug introduced by
It seems like castAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
            return $this->/** @scrutinizer ignore-call */ castAttribute('minimum_order_quantity', $value);
Loading history...
43
        }
44
45 1
        return $this->countMinimumOrderQuantityAttribute();
0 ignored issues
show
Bug introduced by
It seems like countMinimumOrderQuantityAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        return $this->/** @scrutinizer ignore-call */ countMinimumOrderQuantityAttribute();
Loading history...
46
    }
47
48
    /**
49
     * Return "maximum_order_quantity" attribute value.
50
     *
51
     * @param  mixed  $value
52
     * @return int
53
     */
54 2
    public function getMaximumOrderQuantityAttribute($value): int
55
    {
56 2
        if ($this->can_order_custom_quantity) {
57 1
            return $this->castAttribute('maximum_order_quantity', $value);
58
        }
59
60 1
        return $this->countMaximumOrderQuantityAttribute();
0 ignored issues
show
Bug introduced by
It seems like countMaximumOrderQuantityAttribute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        return $this->/** @scrutinizer ignore-call */ countMaximumOrderQuantityAttribute();
Loading history...
61
    }
62
63
    /**
64
     * Return "image" attribute value.
65
     *
66
     * @param  mixed  $value
67
     * @return string
68
     */
69 2
    public function getImageAttribute($value): string
70
    {
71 2
        if (is_null($value)) {
72 1
            return asset('img/dummy.png');
73
        }
74
75 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...
76
    }
77
78
    /**
79
     * Return "range_order_bundle" attribute value.
80
     *
81
     * @return array
82
     */
83 2
    public function getRangeOrderBundleAttribute(): array
84
    {
85 2
        return range($this->minimum_order_bundle, $this->maximum_order_bundle);
86
    }
87
88
    /**
89
     * Return "value_per_bundle" attribute value.
90
     *
91
     * @return float
92
     */
93
    public function getValuePerBundleAttribute(): float
94
    {
95
        return $this->value * $this->quantity_per_bundle;
96
    }
97
98
    /**
99
     * Return "minimum_order_value" attribute value.
100
     *
101
     * @return float
102
     */
103
    public function getMinimumOrderValueAttribute(): float
104
    {
105
        return $this->value_per_bundle * $this->minimum_order_bundle;
106
    }
107
108
    /**
109
     * Return "maximum_order_value" attribute value.
110
     *
111
     * @return float
112
     */
113
    public function getMaximumOrderValueAttribute(): float
114
    {
115
        return $this->value_per_bundle * $this->maximum_order_bundle;
116
    }
117
118
    /**
119
     * Return "value_rupiah" attribute value.
120
     *
121
     * @return string
122
     */
123
    public function getValueRupiahAttribute(): string
124
    {
125
        return format_rupiah($this->value);
126
    }
127
128
    /**
129
     * Return "type_badge" attribute value.
130
     *
131
     * @return string
132
     */
133
    public function getTypeBadgeAttribute(): string
134
    {
135
        return sprintf(<<<'html'
136
            <span class="badge badge-%s">
137
                <i class="fa fa-%s"></i> %s
138
            </span>
139
        html,
140
            $this->type->isCoin() ? 'danger' : 'success',
0 ignored issues
show
Bug introduced by
The method isCoin() does not exist on App\Enum\DenominationType. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

140
            $this->type->/** @scrutinizer ignore-call */ 
141
                         isCoin() ? 'danger' : 'success',
Loading history...
141
            $this->type->isCoin() ? 'coins' : 'money-bill',
142
            $this->type->label
143
        );
144
    }
145
146
    /**
147
     * Return "can_order_custom_quantity_badge" attribute value.
148
     *
149
     * @return string
150
     */
151
    public function getCanOrderCustomQuantityBadgeAttribute(): string
152
    {
153
        return sprintf(<<<'html'
154
            <span class="badge badge-%s">
155
                <i class="fa fa-%s"></i> %s
156
            </span>
157
        html,
158
            $this->can_order_custom_quantity ? 'success' : 'danger',
159
            $this->can_order_custom_quantity ? 'check-circle' : 'times-circle',
160
            $this->can_order_custom_quantity ? trans('Yes') : trans('No')
0 ignored issues
show
Bug introduced by
It seems like $this->can_order_custom_...ns('Yes') : trans('No') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

160
            /** @scrutinizer ignore-type */ $this->can_order_custom_quantity ? trans('Yes') : trans('No')
Loading history...
161
        );
162
    }
163
164
    /**
165
     * Return "is_visible_badge" attribute value.
166
     *
167
     * @return string
168
     */
169
    public function getIsVisibleBadgeAttribute(): string
170
    {
171
        return sprintf(<<<'html'
172
            <span class="badge badge-%s">
173
                <i class="fa fa-%s"></i> %s
174
            </span>
175
        html,
176
            $this->is_visible ? 'success' : 'danger',
177
            $this->is_visible ? 'check-circle' : 'times-circle',
178
            $this->is_visible ? trans('Yes') : trans('No')
0 ignored issues
show
Bug introduced by
It seems like $this->is_visible ? trans('Yes') : trans('No') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

178
            /** @scrutinizer ignore-type */ $this->is_visible ? trans('Yes') : trans('No')
Loading history...
179
        );
180
    }
181
}
182