Skip to content

Commit fc9789d

Browse files
committed
chore: refactor some code
1 parent f80a37c commit fc9789d

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

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/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
}

0 commit comments

Comments
 (0)