Passed
Push — develop ( c02995...7d7bf0 )
by Septianata
18:18
created

OrderStatus::hasBeenCanceled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Models;
4
5
use App\Enum\OrderStatus as EnumOrderStatus;
6
use App\Infrastructure\Database\Eloquent\Model;
7
use App\Models\Contracts\MorphToIssuerable;
8
use Illuminate\Database\Eloquent\Factories\HasFactory;
9
10
class OrderStatus extends Model implements MorphToIssuerable
11
{
12
    use HasFactory,
13
        Concerns\OrderStatus\Attribute,
14
        Concerns\OrderStatus\Relation;
15
16
    /**
17
     * {@inheritDoc}
18
     */
19
    protected $fillable = [
20
        'status',
21
        'note',
22
    ];
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected $casts = [
28
        'status' => EnumOrderStatus::class,
29
    ];
30
31
    /**
32
     * Determine whether the current status is not able to create order schedule.
33
     *
34
     * @return bool
35
     */
36
    public function cantCreateSchedule(): bool
37
    {
38
        return EnumOrderStatus::draft()->equals($this->status);
39
    }
40
41
    /**
42
     * Determine whether the current status is able to create order schedule.
43
     *
44
     * @return bool
45
     */
46
    public function canCreateSchedule(): bool
47
    {
48
        return EnumOrderStatus::on_progress()->equals($this->status);
49
    }
50
51
    /**
52
     * Determine whether the order has been scheduled.
53
     *
54
     * @return bool
55
     */
56
    public function hasBeenScheduled(): bool
57
    {
58
        return
59
            EnumOrderStatus::scheduled()->equals($this->status) ||
60
            EnumOrderStatus::rescheduled()->equals($this->status);
61
    }
62
63
    /**
64
     * Determine whether the order has been finished.
65
     *
66
     * @return bool
67
     */
68
    public function hasBeenFinished(): bool
69
    {
70
        return EnumOrderStatus::finished()->equals($this->status);
71
    }
72
73
    /**
74
     * Determine whether the order has been canceled.
75
     *
76
     * @return bool
77
     */
78
    public function hasBeenCanceled(): bool
79
    {
80
        return EnumOrderStatus::canceled()->equals($this->status);
81
    }
82
}
83