1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ShippoClient\Entity; |
4
|
|
|
|
5
|
|
|
use TurmericSpice\ReadableAttributes; |
6
|
|
|
|
7
|
|
|
class TrackingStatus |
8
|
|
|
{ |
9
|
|
|
use ReadableAttributes { |
10
|
|
|
mayHaveAsString as public getStatusDetails; |
11
|
|
|
mayHaveAsString as public getStatusDate; |
12
|
|
|
toArray as __toArray; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Date and time of object creation. |
17
|
|
|
* |
18
|
|
|
* @return \DateTime |
19
|
|
|
*/ |
20
|
|
|
public function getObjectCreated() |
21
|
|
|
{ |
22
|
|
|
return $this->attributes->mayHave('object_created')->asInstanceOf('\\DateTime'); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Date and time of last object update. |
27
|
|
|
* |
28
|
|
|
* @return \DateTime |
29
|
|
|
*/ |
30
|
|
|
public function getObjectUpdated() |
31
|
|
|
{ |
32
|
|
|
return $this->attributes->mayHave('object_updated')->asInstanceOf('\\DateTime'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Unique identifier of the given object. |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function getObjectId() |
41
|
|
|
{ |
42
|
|
|
return $this->attributes->mayHave('object_id')->asString(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Package status. |
47
|
|
|
* - "UNKNOWN" The package has not been found via the carrier's tracking system, |
48
|
|
|
* or it has been found but not yet scanned by the carrier. |
49
|
|
|
* - "TRANSIT" The package has been scanned by the carrier and is in transit. |
50
|
|
|
* - "DELIVERED" The package has been successfully delivered. |
51
|
|
|
* - "RETURNED" The package is en route to be returned to the sender, or has been returned successfully. |
52
|
|
|
* - "FAILURE" The carrier indicated that there has been an issue with the delivery. |
53
|
|
|
* This can happen for various reasons and depends on the carrier. |
54
|
|
|
* This status does not indicate a technical error, but rather a delivery issue. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getStatus() |
59
|
|
|
{ |
60
|
|
|
return $this->attributes->mayHave('status')->asString(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return Location |
65
|
|
|
*/ |
66
|
|
|
public function getLocation() |
67
|
|
|
{ |
68
|
|
|
$attributes = $this->attributes->mayHave('location')->asArray(); |
69
|
|
|
return new Location($attributes); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function toArray() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
'object_created' => $this->getObjectCreated(), |
76
|
|
|
'object_updated' => $this->getObjectUpdated(), |
77
|
|
|
'object_id' => $this->getObjectId(), |
78
|
|
|
'status' => $this->getStatus(), |
79
|
|
|
'status_date' => $this->getStatusDate(), |
80
|
|
|
'status_details' => $this->getStatusDetails(), |
|
|
|
|
81
|
|
|
'location' => $this->getLocation()->toArray(), |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: