Passed
Push — master ( d53d6f...24ad68 )
by Tomáš
09:09
created

Status::isDelivered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
     * @var float
15
     */
16
    public const ORDERED = -1.0;
17
18
    /**
19
     * Picked up at the sender
20
     *
21
     * @var float
22
     */
23
    public const PICKED_UP_FROM_SENDER = 2.1;
24
25
    /**
26
     * Transit
27
     *
28
     * @var float
29
     */
30
    public const TRANSIT = 2.2;
31
32
    /**
33
     * Ready to pick up
34
     *
35
     * @var float
36
     */
37
    public const READY_TO_PICK_UP = 2.3;
38
39
    /**
40
     * Back on the way to the sender
41
     *
42
     * @var float
43
     */
44
    public const SEND_BACK_TO_SENDER = 2.4;
45
46
    /**
47
     * Handed over to the final carrier
48
     *
49
     * @var float
50
     */
51
    public const HANDED_TO_FINAL_SHIPPER = 2.5;
52
53
    /**
54
     * Cancellation by the carrier
55
     *
56
     * @var float
57
     */
58
    public const CANCELLATION_BY_SHIPPER = 3.1;
59
60
    /**
61
     * Cancellation by the recipient
62
     *
63
     * @var float
64
     */
65
    public const CANCELLATION_BY_RECIPIENT = 3.2;
66
67
    /**
68
     * Cancellation by the sender
69
     *
70
     * @var float
71
     */
72
    public const CANCELLATION_BY_SENDER = 3.3;
73
74
    /**
75
     * Delivered back to sender
76
     *
77
     * @var float
78
     */
79
    public const DELIVERED_BACK_TO_SENDER = 4.0;
80
81
    /**
82
     * Cash on delivery has been credited to the sender's account
83
     *
84
     * @var float
85
     */
86
    public const COD_PAID = 5.0;
87
88
    /**
89
     * Carrier error
90
     *
91
     * @var float
92
     */
93
    public const ERROR_SHIPPER = 0.1;
94
95
    /**
96
     * Error on the part of the recipient
97
     *
98
     * @var float
99
     */
100
    public const ERROR_RECIPIENT = 0.2;
101
102
    /**
103
     * Error on the part of the sender
104
     *
105
     * @var float
106
     */
107
    public const ERROR_SENDER = 0.3;
108
109
    /**
110
     * Collection of the consignment at the delivery point
111
     *
112
     * @var float
113
     */
114
    public const PICKUP_ON_DELIVERY_POINT = 1.1;
115
116
    /**
117
     * Delivered to address
118
     *
119
     * @var float
120
     */
121
    public const DELIVERED_TO_ADDRESS = 1.2;
122
123
    /**
124
     * Is package delivered to customer
125
     *
126
     * @param float $status
127
     *
128
     * @return bool
129
     */
130
    public static function isDelivered(float $status): bool
131
    {
132
        return self::inStatuses($status, [
133
            self::PICKUP_ON_DELIVERY_POINT,
134
            self::DELIVERED_TO_ADDRESS,
135
        ]);
136
    }
137
138
    /**
139
     * Package delivery failed
140
     *
141
     * @param float $status
142
     *
143
     * @return bool
144
     */
145
    public static function isError(float $status): bool
146
    {
147
        return self::inStatuses($status, [
148
            self::ERROR_SHIPPER,
149
            self::ERROR_RECIPIENT,
150
            self::ERROR_SENDER,
151
        ]);
152
    }
153
154
    /**
155
     * Package is being delivered to customer
156
     *
157
     * @param float $status
158
     *
159
     * @return bool
160
     */
161
    public static function isBeingDelivered(float $status): bool
162
    {
163
        return self::inStatuses($status, [
164
            self::ORDERED,
165
            self::PICKED_UP_FROM_SENDER,
166
            self::TRANSIT,
167
            self::READY_TO_PICK_UP,
168
            self::HANDED_TO_FINAL_SHIPPER,
169
        ]);
170
    }
171
172
    /**
173
     * Package delivery processed ended
174
     *
175
     * @param float $status
176
     *
177
     * @return bool
178
     */
179
    public static function isClosed(float $status): bool
180
    {
181
        return self::inStatuses($status, [
182
            self::DELIVERED_BACK_TO_SENDER,
183
            self::COD_PAID,
184
            self::PICKUP_ON_DELIVERY_POINT,
185
            self::DELIVERED_TO_ADDRESS,
186
        ]);
187
    }
188
189
    /**
190
     * Check if given ID is in any of given statuses
191
     *
192
     * @param float        $status
193
     * @param array<float> $statuses
194
     *
195
     * @return bool
196
     */
197
    private static function inStatuses(float $status, array $statuses): bool
198
    {
199
        return in_array($status, $statuses, true);
200
    }
201
}
202