Passed
Push — develop ( dcecff...37402c )
by Septianata
16:01
created

getIsOrderCustomQuantityBadgeAttribute()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 10
cc 4
nc 1
nop 0
crap 20
1
<?php
2
3
namespace App\Models\Concerns\Item;
4
5
/**
6
 * @property int $quantity_per_bundle
7
 * @property int|null $bundle_quantity
8
 * @property int $quantity
9
 * @property bool $is_order_custom_quantity
10
 * @property-read string $denomination_name
11
 * @property-read float $denomination_value
12
 * @property-read float $total
13
 * @property-read string $is_order_custom_quantity_badge
14
 *
15
 * @see \App\Models\Item
16
 */
17
trait Attribute
18
{
19
    /**
20
     * Return "quantity" attribute value.
21
     *
22
     * @param  mixed  $value
23
     * @return int
24
     */
25
    public function getQuantityAttribute($value): int
26
    {
27
        if ($this->is_order_custom_quantity) {
28
            return $this->castAttribute('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

28
            return $this->/** @scrutinizer ignore-call */ castAttribute('quantity', $value);
Loading history...
29
        }
30
31
        return $this->countQuantityAttribute();
0 ignored issues
show
Bug introduced by
It seems like countQuantityAttribute() 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

31
        return $this->/** @scrutinizer ignore-call */ countQuantityAttribute();
Loading history...
32
    }
33
34
    /**
35
     * Return "denomination_name" attribute value.
36
     *
37
     * @return string
38
     */
39
    public function getDenominationNameAttribute(): string
40
    {
41
        return $this->denomination->name;
0 ignored issues
show
Bug introduced by
The property denomination does not exist on App\Models\Concerns\Item\Attribute. Did you mean denomination_value?
Loading history...
42
    }
43
44
    /**
45
     * Return "denomination_value" attribute value.
46
     *
47
     * @return float
48
     */
49
    public function getDenominationValueAttribute(): float
50
    {
51
        return $this->denomination->value;
0 ignored issues
show
Bug introduced by
The property denomination does not exist on App\Models\Concerns\Item\Attribute. Did you mean denomination_value?
Loading history...
52
    }
53
54
    /**
55
     * Return "total" attribute value.
56
     *
57
     * @return float
58
     */
59
    public function getTotalAttribute(): float
60
    {
61
        return $this->quantity * $this->denomination_value;
62
    }
63
64
    /**
65
     * Return "is_order_custom_quantity_badge" attribute value.
66
     *
67
     * @return string
68
     */
69
    public function getIsOrderCustomQuantityBadgeAttribute(): string
70
    {
71
        return sprintf(<<<'html'
72
            <span class="badge badge-%s">
73
                <i class="fa fa-%s"></i> %s
74
            </span>
75
        html,
76
            $this->is_order_custom_quantity ? 'success' : 'danger',
77
            $this->is_order_custom_quantity ? 'check-circle' : 'times-circle',
78
            $this->is_order_custom_quantity ? trans('Yes') : trans('No')
0 ignored issues
show
Bug introduced by
It seems like $this->is_order_custom_q...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

78
            /** @scrutinizer ignore-type */ $this->is_order_custom_quantity ? trans('Yes') : trans('No')
Loading history...
79
        );
80
    }
81
}
82