1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ShippoClient\Entity; |
4
|
|
|
|
5
|
|
|
use TurmericSpice\ReadableAttributes; |
6
|
|
|
|
7
|
|
|
class Tracks |
8
|
|
|
{ |
9
|
|
|
use ReadableAttributes { |
10
|
|
|
mayHaveAsString as public getCarrier; |
11
|
|
|
mayHaveAsString as public getTrackingNumber; |
12
|
|
|
mayHaveAsString as public getEta; |
13
|
|
|
toArray as public __toArray; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @return \ShippoClient\Entity\TrackingStatus |
18
|
|
|
*/ |
19
|
|
|
public function getTrackingStatus() |
20
|
|
|
{ |
21
|
|
|
return new TrackingStatus($this->attributes->mayHave('tracking_status')->asArray()); |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return \ShippoClient\Entity\TrackingHistory |
26
|
|
|
*/ |
27
|
|
|
public function getTrackingHistory() |
28
|
|
|
{ |
29
|
|
|
$entities = $this->attributes->mayHave('tracking_history') |
30
|
|
|
->asInstanceArray('ShippoClient\\Entity\\TrackingStatus'); |
31
|
|
|
|
32
|
|
|
return new TrackingHistory($entities); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return \ShippoClient\Entity\Location |
37
|
|
|
*/ |
38
|
|
|
public function getAddressFrom() |
39
|
|
|
{ |
40
|
|
|
$addressFrom = $this->attributes->mayHave('address_from')->asArray(); |
41
|
|
|
|
42
|
|
|
return new Location($addressFrom); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return \ShippoClient\Entity\Location |
47
|
|
|
*/ |
48
|
|
|
public function getAddressTo() |
49
|
|
|
{ |
50
|
|
|
$addressTo = $this->attributes->mayHave('address_to')->asArray(); |
51
|
|
|
|
52
|
|
|
return new Location($addressTo); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return \ShippoClient\Entity\ServiceLevel |
57
|
|
|
*/ |
58
|
|
|
public function getServiceLevel() |
59
|
|
|
{ |
60
|
|
|
$serviceLevel = $this->attributes->mayHave('servicelevel')->asArray(); |
61
|
|
|
|
62
|
|
|
return new ServiceLevel($serviceLevel); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function toArray() |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'carrier' => $this->getCarrier(), |
|
|
|
|
69
|
|
|
'tracking_number' => $this->getTrackingNumber(), |
|
|
|
|
70
|
|
|
'tracking_status' => $this->getTrackingStatus()->toArray(), |
71
|
|
|
'tracking_history' => $this->getTrackingHistory()->toArray(), |
72
|
|
|
'eta' => $this->getEta(), |
73
|
|
|
'address_from' => $this->getAddressFrom()->toArray(), |
74
|
|
|
'address_to' => $this->getAddressTo()->toArray(), |
75
|
|
|
'servicelevel' => $this->getServiceLevel()->toArray(), |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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: