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

OrderStatus   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 0
f 0
dl 0
loc 71
ccs 0
cts 11
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreateSchedule() 0 3 1
A hasBeenCanceled() 0 3 1
A hasBeenScheduled() 0 5 2
A hasBeenFinished() 0 3 1
A cantCreateSchedule() 0 3 1
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