Skip to content

Commit 93abf11

Browse files
authored
Merge pull request #92 from annuh/always-validate-response
chore: always validate reponse from PostNL
2 parents 02e6b8f + fc9789d commit 93abf11

5 files changed

Lines changed: 11 additions & 11 deletions

src/Service/ResponseProcessor/Rest/BarcodeServiceRestResponseProcessor.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,12 @@ class BarcodeServiceRestResponseProcessor extends AbstractRestResponseProcessor
6363
public function processGenerateBarcodeResponse(ResponseInterface $response): string
6464
{
6565
$this->validateResponse(response: $response);
66-
$responseContent = $this->getResponseText(response: $response);
66+
$body = json_decode(json: static::getResponseText(response: $response));
6767

68-
try {
69-
$json = json_decode(json: $responseContent, flags: JSON_THROW_ON_ERROR);
70-
} catch (JsonException $e) {
71-
throw new ResponseException(message: 'Invalid API Response', previous: $e, response: $response);
72-
}
73-
74-
if (!isset($json->Barcode)) {
68+
if (!isset($body->Barcode)) {
7569
throw new ResponseException(message: 'Invalid API Response', response: $response);
7670
}
7771

78-
return $json->Barcode;
72+
return $body->Barcode;
7973
}
8074
}

src/Service/ResponseProcessor/Rest/DeliveryDateServiceRestResponseProcessor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class DeliveryDateServiceRestResponseProcessor extends AbstractRestResponseProce
6565
*/
6666
public function processGetDeliveryDateResponse(ResponseInterface $response): GetDeliveryDateResponse
6767
{
68+
$this->validateResponse(response: $response);
6869
$body = json_decode(json: static::getResponseText(response: $response));
6970
if (isset($body->DeliveryDate)) {
7071
return GetDeliveryDateResponse::jsonDeserialize(json: (object) ['GetDeliveryDateResponse' => $body]);
@@ -91,6 +92,7 @@ public function processGetDeliveryDateResponse(ResponseInterface $response): Get
9192
*/
9293
public function processGetSentDateResponse(ResponseInterface $response): GetSentDateResponse
9394
{
95+
$this->validateResponse(response: $response);
9496
$body = json_decode(json: static::getResponseText(response: $response));
9597
if (isset($body->SentDate)) {
9698
return GetSentDateResponse::jsonDeserialize(json: (object) ['GetSentDateResponse' => $body]);

src/Service/ResponseProcessor/Rest/LabellingServiceRestResponseProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class LabellingServiceRestResponseProcessor extends AbstractRestResponseProcesso
6565
public function processGenerateLabelResponse(ResponseInterface $response): GenerateLabelResponse
6666
{
6767
$this->validateResponse(response: $response);
68-
$responseContent = static::getResponseText(response: $response);
69-
$body = json_decode(json: $responseContent);
68+
$body = json_decode(json: static::getResponseText(response: $response));
69+
7070
if (isset($body->ResponseShipments)) {
7171
return GenerateLabelResponse::jsonDeserialize(json: (object) ['GenerateLabelResponse' => $body]);
7272
}

src/Service/ResponseProcessor/Rest/ShippingServiceRestResponseProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ShippingServiceRestResponseProcessor extends AbstractRestResponseProcessor
6262
*/
6363
public function processSendShipmentResponse(ResponseInterface $response): ?SendShipmentResponse
6464
{
65+
$this->validateResponse(response: $response);
6566
$body = json_decode(json: static::getResponseText(response: $response));
6667
if (isset($body->ResponseShipments)) {
6768
return SendShipmentResponse::JsonDeserialize(json: (object) ['SendShipmentResponse' => $body]);

src/Service/ResponseProcessor/Rest/ShippingStatusServiceRestResponseProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class ShippingStatusServiceRestResponseProcessor extends AbstractRestResponsePro
7171
*/
7272
public function processCurrentStatusResponse(ResponseInterface $response): CurrentStatusResponse
7373
{
74+
$this->validateResponse(response: $response);
7475
$body = json_decode(json: static::getResponseText(response: $response));
7576

7677
/* @var CurrentStatusResponse $object */
@@ -189,6 +190,7 @@ public function processCompleteStatusResponse(ResponseInterface $response): Comp
189190
*/
190191
public function processGetSignatureResponse(ResponseInterface $response): GetSignatureResponseSignature
191192
{
193+
$this->validateResponse(response: $response);
192194
$body = json_decode(json: static::getResponseText(response: $response));
193195

194196
/* @var GetSignatureResponseSignature $object */
@@ -212,6 +214,7 @@ public function processGetSignatureResponse(ResponseInterface $response): GetSig
212214
*/
213215
public function processGetUpdatedShipmentsResponse(ResponseInterface $response): array
214216
{
217+
$this->validateResponse(response: $response);
215218
$body = json_decode(json: static::getResponseText(response: $response));
216219
if (!is_array(value: $body)) {
217220
return [];

0 commit comments

Comments
 (0)