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