Status::isDelivered()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Definitions;
6
7
use function in_array;
8
9
final class Status
10
{
11
    /**
12
     * Ordered
13
     */
14
    public const ORDERED = -1.0;
15
16
    /**
17
     * Picked up at the sender
18
     */
19
    public const PICKED_UP_FROM_SENDER = 2.1;
20
21
    /**
22
     * Transit
23
     */
24
    public const TRANSIT = 2.2;
25
26
    /**
27
     * Ready to pick up
28
     */
29
    public const READY_TO_PICK_UP = 2.3;
30
31
    /**
32
     * Back on the way to the sender
33
     */
34
    public const SEND_BACK_TO_SENDER = 2.4;
35
36
    /**
37
     * Handed over to the final carrier
38
     */
39
    public const HANDED_TO_FINAL_CARRIER = 2.5;
40
41
    /**
42
     * Cancellation by the carrier
43
     */
44
    public const CANCELLATION_BY_CARRIER = 3.1;
45
46
    /**
47
     * Cancellation by the recipient
48
     */
49
    public const CANCELLATION_BY_RECIPIENT = 3.2;
50
51
    /**
52
     * Cancellation by the sender
53
     */
54
    public const CANCELLATION_BY_SENDER = 3.3;
55
56
    /**
57
     * Delivered back to sender
58
     */
59
    public const DELIVERED_BACK_TO_SENDER = 4.0;
60
61
    /**
62
     * Cash on delivery has been credited to the sender's account
63
     */
64
    public const COD_PAID = 5.0;
65
66
    /**
67
     * Carrier error
68
     */
69
    public const ERROR_CARRIER = 0.1;
70
71
    /**
72
     * Error on the part of the recipient
73
     */
74
    public const ERROR_RECIPIENT = 0.2;
75
76
    /**
77
     * Error on the part of the sender
78
     */
79
    public const ERROR_SENDER = 0.3;
80
81
    /**
82
     * Collection of the consignment at the delivery point
83
     */
84
    public const PICKUP_ON_DELIVERY_POINT = 1.1;
85
86
    /**
87
     * Delivered to address
88
     */
89
    public const DELIVERED_TO_ADDRESS = 1.2;
90
91
    /**
92
     * Is package delivered to customer
93
     */
94
    public static function isDelivered(float $status): bool
95
    {
96
        return self::isStatus($status, [
97
            self::PICKUP_ON_DELIVERY_POINT,
98
            self::DELIVERED_TO_ADDRESS,
99
        ]);
100
    }
101
102
    /**
103
     * Package delivery failed
104
     */
105
    public static function isError(float $status): bool
106
    {
107
        return self::isStatus($status, [
108
            self::ERROR_CARRIER,
109
            self::ERROR_RECIPIENT,
110
            self::ERROR_SENDER,
111
        ]);
112
    }
113
114
    /**
115
     * Package is being delivered to customer
116
     */
117
    public static function isBeingDelivered(float $status): bool
118
    {
119
        return self::isStatus($status, [
120
            self::ORDERED,
121
            self::PICKED_UP_FROM_SENDER,
122
            self::TRANSIT,
123
            self::READY_TO_PICK_UP,
124
            self::HANDED_TO_FINAL_CARRIER,
125
        ]);
126
    }
127
128
    /**
129
     * Package delivery processed ended
130
     */
131
    public static function isClosed(float $status): bool
132
    {
133
        return self::isStatus($status, [
134
            self::DELIVERED_BACK_TO_SENDER,
135
            self::COD_PAID,
136
            self::PICKUP_ON_DELIVERY_POINT,
137
            self::DELIVERED_TO_ADDRESS,
138
        ]);
139
    }
140
141
    /**
142
     * Check if given ID is in any of given statuses
143
     *
144
     * @param array<float> $statuses
145
     */
146
    private static function isStatus(float $status, array $statuses): bool
147
    {
148
        return in_array($status, $statuses, true);
149
    }
150
}
151