From 2a14c65ec9e4263fcbdeffda0e6c07bdce7c23e8 Mon Sep 17 00:00:00 2001 From: rimvydas Date: Mon, 11 Nov 2024 14:31:31 +0200 Subject: [PATCH 1/3] Added generator for requests --- src/Utils.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index b80a77a..6aeae6e 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -39,7 +39,7 @@ final class Utils * @throws CriticalException * */ - public static function sendIterableRequest(Client $client, Request $request, Config $config): array + public static function sendIterableRequest(Client $client, Request $request, Config $config): \Generator { if (!$request instanceof IterableRequestInterface) { throw new InvalidArgumentException(sprintf( @@ -48,7 +48,6 @@ public static function sendIterableRequest(Client $client, Request $request, Con )); } - $responses = []; $lastPage = false; $request->setItemsPerPage($config->getItemsPerPage()); @@ -57,10 +56,8 @@ public static function sendIterableRequest(Client $client, Request $request, Con $lastPage = self::parseIsLastPage($response); $request->setPage($request->getPage() + 1); - $responses[] = $response; + yield $response; } - - return $responses; } public static function validateAndGetShopkey(?string $shopkey): ?string From 18ef1e8abf018acc0761d6737443513f4580fe5c Mon Sep 17 00:00:00 2001 From: rimvydas Date: Wed, 13 Nov 2024 12:31:29 +0200 Subject: [PATCH 2/3] fix linting problems --- bin/console | 0 src/Utils.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 bin/console diff --git a/bin/console b/bin/console old mode 100755 new mode 100644 diff --git a/src/Utils.php b/src/Utils.php index 6aeae6e..2becbd5 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -29,7 +29,7 @@ final class Utils * @param Client $client * @param Request $request * - * @return ResponseInterface[] + * @return \Generator * @throws EmptyResponseException * @throws PermissionException * @throws CustomerException From 43b099450a6d8c01e6469f4576a8b615e1c2f5c6 Mon Sep 17 00:00:00 2001 From: rimvydas Date: Wed, 13 Nov 2024 23:58:33 +0200 Subject: [PATCH 3/3] lint fix, update test --- tests/UtilsTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 3aa1f7a..661a6da 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -12,6 +12,7 @@ use FINDOLOGIC\PlentyMarketsRestExporter\Tests\Helper\DirectoryAware; use FINDOLOGIC\PlentyMarketsRestExporter\Tests\Helper\ResponseHelper; use FINDOLOGIC\PlentyMarketsRestExporter\Utils; +use Psr\Http\Message\ResponseInterface; use GuzzleHttp\Client; use InvalidArgumentException; use PHPUnit\Framework\MockObject\MockObject; @@ -260,6 +261,8 @@ public function testSendIterableRequestFailsForNonIterableRequests(): void ->disableOriginalConstructor() ->getMock(); - Utils::sendIterableRequest($client, $nonIterableRequest, $config); + foreach (Utils::sendIterableRequest($client, $nonIterableRequest, $config) as $response) { + $this->assertInstanceOf(ResponseInterface::class, $response); + }; } }