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
|
|
|
toArray as __toArray; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Date and time of object creation. |
16
|
|
|
* |
17
|
|
|
* @return \DateTime |
18
|
|
|
*/ |
19
|
|
|
public function getObjectCreated() |
20
|
|
|
{ |
21
|
|
|
return $this->attributes->mayHave('object_created')->asInstanceOf('\\DateTime'); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Date and time of last object update. |
26
|
|
|
* |
27
|
|
|
* @return \DateTime |
28
|
|
|
*/ |
29
|
|
|
public function getObjectUpdated() |
30
|
|
|
{ |
31
|
|
|
return $this->attributes->mayHave('object_updated')->asInstanceOf('\\DateTime'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Date and time when the carrier has scanned this tracking event. |
36
|
|
|
* |
37
|
|
|
* @return \DateTime |
38
|
|
|
*/ |
39
|
|
|
public function getStatusDate() |
40
|
|
|
{ |
41
|
|
|
return $this->attributes->mayHave('status_date')->asInstanceOf('\\DateTime'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Unique identifier of the given object. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getObjectId() |
50
|
|
|
{ |
51
|
|
|
return $this->attributes->mayHave('object_id')->asString(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Package status. |
56
|
|
|
* - "UNKNOWN" The package has not been found via the carrier's tracking system, |
57
|
|
|
* or it has been found but not yet scanned by the carrier. |
58
|
|
|
* - "TRANSIT" The package has been scanned by the carrier and is in transit. |
59
|
|
|
* - "DELIVERED" The package has been successfully delivered. |
60
|
|
|
* - "RETURNED" The package is en route to be returned to the sender, or has been returned successfully. |
61
|
|
|
* - "FAILURE" The carrier indicated that there has been an issue with the delivery. |
62
|
|
|
* This can happen for various reasons and depends on the carrier. |
63
|
|
|
* This status does not indicate a technical error, but rather a delivery issue. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getStatus() |
68
|
|
|
{ |
69
|
|
|
return $this->attributes->mayHave('status')->asString(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return Location |
74
|
|
|
*/ |
75
|
|
|
public function getLocation() |
76
|
|
|
{ |
77
|
|
|
$attributes = $this->attributes->mayHave('location')->asArray(); |
78
|
|
|
return new Location($attributes); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function toArray() |
82
|
|
|
{ |
83
|
|
|
return [ |
84
|
|
|
'object_created' => $this->getObjectCreated(), |
85
|
|
|
'object_updated' => $this->getObjectUpdated(), |
86
|
|
|
'object_id' => $this->getObjectId(), |
87
|
|
|
'status' => $this->getStatus(), |
88
|
|
|
'status_date' => $this->getStatusDate(), |
89
|
|
|
'status_details' => $this->getStatusDetails(), |
90
|
|
|
'location' => $this->getLocation()->toArray(), |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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: