From 6da5aa7ceb522d8280f2d8b192ef334d1350cfae Mon Sep 17 00:00:00 2001 From: Milan Blagojevic Date: Tue, 23 May 2023 15:59:01 +0200 Subject: [PATCH 1/3] IT-10656 Handling situation when 'results' key is missing in response --- src/Arbor/Api/Gateway/RestGateway.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Arbor/Api/Gateway/RestGateway.php b/src/Arbor/Api/Gateway/RestGateway.php index 37eb44c..efa29df 100755 --- a/src/Arbor/Api/Gateway/RestGateway.php +++ b/src/Arbor/Api/Gateway/RestGateway.php @@ -302,6 +302,10 @@ public function bulkCreate(string $resource, Collection $collection, bool $check } if (isset($exception)) { + if (!isset($responseRepresentation['results'])) { + $responseRepresentation['results'] = []; + } + $failedResponses = array_reduce($responseRepresentation['results'], static function ($responses, $item) { if (isset($item['status']) && $item['status']['success'] === false) { $responses[] = $item['status']; From 05df4879382886f77aa004f5e12ea54ffaa2f1b7 Mon Sep 17 00:00:00 2001 From: Milan Blagojevic Date: Wed, 31 May 2023 15:15:16 +0200 Subject: [PATCH 2/3] IT-10656 Used null coalescing operator as it's supporter from PHP 7.0 and inline with PHP version in composer.json --- src/Arbor/Api/Gateway/RestGateway.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Arbor/Api/Gateway/RestGateway.php b/src/Arbor/Api/Gateway/RestGateway.php index efa29df..abd9fa6 100755 --- a/src/Arbor/Api/Gateway/RestGateway.php +++ b/src/Arbor/Api/Gateway/RestGateway.php @@ -302,11 +302,7 @@ public function bulkCreate(string $resource, Collection $collection, bool $check } if (isset($exception)) { - if (!isset($responseRepresentation['results'])) { - $responseRepresentation['results'] = []; - } - - $failedResponses = array_reduce($responseRepresentation['results'], static function ($responses, $item) { + $failedResponses = array_reduce($responseRepresentation['results'] ?? [], static function ($responses, $item) { if (isset($item['status']) && $item['status']['success'] === false) { $responses[] = $item['status']; } From 923aa3b4f92ff61f2c7bdab0541d391a7a34716a Mon Sep 17 00:00:00 2001 From: Milan Blagojevic Date: Thu, 1 Jun 2023 09:21:08 +0200 Subject: [PATCH 3/3] IT-10656 Refactored catch block --- src/Arbor/Api/Gateway/RestGateway.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Arbor/Api/Gateway/RestGateway.php b/src/Arbor/Api/Gateway/RestGateway.php index abd9fa6..0373813 100755 --- a/src/Arbor/Api/Gateway/RestGateway.php +++ b/src/Arbor/Api/Gateway/RestGateway.php @@ -293,15 +293,11 @@ public function bulkCreate(string $resource, Collection $collection, bool $check $options['body']['request'][] = [$resourceRoot => $arrayRepresentation]; } - $exception = null; - try { $responseRepresentation = $this->sendRequest(self::HTTP_METHOD_POST, "/rest-v2/$resourceUrl", $options); } catch (ServerErrorException $exception) { $responseRepresentation = $exception->getResponsePayload(); - } - if (isset($exception)) { $failedResponses = array_reduce($responseRepresentation['results'] ?? [], static function ($responses, $item) { if (isset($item['status']) && $item['status']['success'] === false) { $responses[] = $item['status'];