Skip to content

Commit a8967af

Browse files
authored
Merge pull request #8 from tpeyrou-clever/dev
Add toArray to Event and Step classes + Return error code into Tracki…
2 parents 6eb8379 + 46884fe commit a8967af

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Model/Tracking/Response/Event.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,15 @@ public function setSiteZipCode(?string $siteZipCode): Event
7171

7272
return $this;
7373
}
74+
75+
public function toArray(): array
76+
{
77+
return [
78+
'date' => $this->getDate(),
79+
'code' => $this->getCode(),
80+
'labelLong' => $this->getLabelLong(),
81+
'siteName' => $this->getSiteName(),
82+
'siteZipCode' => $this->getSiteZipCode(),
83+
];
84+
}
7485
}

Model/Tracking/Response/Step.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,16 @@ public function setDate(?string $date): Step
9999

100100
return $this;
101101
}
102+
103+
public function toArray(): array
104+
{
105+
return [
106+
'id' => $this->getStepId(),
107+
'stepLabel' => $this->getStepLabel(),
108+
'longLabel' => $this->getLongLabel(),
109+
'status' => $this->getStatus(),
110+
'country' => $this->getCountry(),
111+
'date' => $this->getDate(),
112+
];
113+
}
102114
}

Service/TrackingService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ public function validateDataBeforeCall(array $dataToValidate): void
4141
}
4242
}
4343

44+
/**
45+
* @throws TrackingRequestException
46+
*/
4447
public function parseResponse($response): TrackingResponse
4548
{
4649
$responses = $this->slsResponseParser->parse($response);
4750

4851
$body = $responses[0]['body'];
4952
$status = $body['status'][0];
5053
if ($status['code'] !== "0") {
51-
throw new TrackingRequestException($status['message']);
54+
throw new TrackingRequestException($status['message'], $status['code']);
5255
}
5356

5457
$parcel = $body['parcel'];

0 commit comments

Comments
 (0)