diff --git a/bootstrap.php b/bootstrap.php index 5e9e82e..593071d 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -3,6 +3,6 @@ use Cerbero\LazyJsonPages\LazyJsonPages; use Illuminate\Support\LazyCollection; -(static function() { +(static function () { LazyCollection::macro('fromJsonPages', [LazyJsonPages::class, 'from']); })(); diff --git a/src/Concerns/SendsAsyncRequests.php b/src/Concerns/SendsAsyncRequests.php index 273ff7a..25c8a5c 100644 --- a/src/Concerns/SendsAsyncRequests.php +++ b/src/Concerns/SendsAsyncRequests.php @@ -32,7 +32,7 @@ protected function fetchPagesAsynchronously(int $totalPages): Generator $fromPage = $this->config->firstPage + 1; $toPage = $this->config->firstPage == 0 ? $totalPages - 1 : $totalPages; - yield from $this->retry(function() use ($request, &$fromPage, $toPage) { + yield from $this->retry(function () use ($request, &$fromPage, $toPage) { foreach ($this->chunkRequestsBetweenPages($request, $fromPage, $toPage) as $requests) { yield from $this->pool($requests); } @@ -83,7 +83,7 @@ protected function pool(Generator $requests): Generator $config = [ 'concurrency' => $this->config->async, 'fulfilled' => fn(ResponseInterface $response, int $page) => $this->book->addPage($page, $response), - 'rejected' => function(Throwable $e, int $page) use (&$exception) { + 'rejected' => function (Throwable $e, int $page) use (&$exception) { $this->book->addFailedPage($page); $exception = $e; }, diff --git a/src/Concerns/YieldsItemsByCursor.php b/src/Concerns/YieldsItemsByCursor.php index 2ae9a8f..df3a426 100644 --- a/src/Concerns/YieldsItemsByCursor.php +++ b/src/Concerns/YieldsItemsByCursor.php @@ -28,7 +28,7 @@ protected function yieldItemsByCursor(Closure $callback): Generator yield from $generator = $callback($this->source->pullResponse()); - yield from $this->retry(function() use ($callback, $request, $generator) { + yield from $this->retry(function () use ($callback, $request, $generator) { while ($cursor = $this->toPage($generator->getReturn(), onlyNumerics: false)) { $this->respectRateLimits(); diff --git a/src/Concerns/YieldsItemsByLength.php b/src/Concerns/YieldsItemsByLength.php index 188e995..c9351f6 100644 --- a/src/Concerns/YieldsItemsByLength.php +++ b/src/Concerns/YieldsItemsByLength.php @@ -24,7 +24,7 @@ trait YieldsItemsByLength */ protected function yieldItemsUntilKey(string $key, ?Closure $callback = null): Generator { - yield from $this->yieldItemsUntilPage(function(ResponseInterface $response) use ($key, $callback) { + yield from $this->yieldItemsUntilPage(function (ResponseInterface $response) use ($key, $callback) { yield from $generator = $this->yieldItemsAndGetKey($response, $key); if (!is_int($page = $this->toPage($generator->getReturn()))) { diff --git a/src/Data/RateLimit.php b/src/Data/RateLimit.php index 99ecb29..68f24e9 100644 --- a/src/Data/RateLimit.php +++ b/src/Data/RateLimit.php @@ -25,8 +25,7 @@ final class RateLimit public function __construct( public readonly int $requests, public readonly int $perSeconds, - ) { - } + ) {} /** * Update the requests sent before this rate limit resets. diff --git a/src/LazyJsonPages.php b/src/LazyJsonPages.php index a8c23f7..80f2bb4 100644 --- a/src/LazyJsonPages.php +++ b/src/LazyJsonPages.php @@ -283,7 +283,7 @@ public function collect(string $dot = '*'): LazyCollection { $this->config[Config::OPTION_ITEMS_POINTER] = DotsConverter::toPointer($dot); - return new LazyCollection(function() { + return new LazyCollection(function () { $client = $this->client->make(); $config = new Config(...$this->config); $source = (new AnySource($this->source))->setClient($client); diff --git a/src/Middleware/Tap.php b/src/Middleware/Tap.php index b5b5480..3b00d18 100644 --- a/src/Middleware/Tap.php +++ b/src/Middleware/Tap.php @@ -45,9 +45,7 @@ public static function once(?Closure $onRequest = null, ?Closure $onResponse = n /** * Instantiate the class. */ - public function __construct(private readonly TapCallbacks $callbacks) - { - } + public function __construct(private readonly TapCallbacks $callbacks) {} /** * Handle an HTTP request before and after it is sent. diff --git a/src/Paginations/CursorAwarePagination.php b/src/Paginations/CursorAwarePagination.php index 2448b14..076bf9d 100644 --- a/src/Paginations/CursorAwarePagination.php +++ b/src/Paginations/CursorAwarePagination.php @@ -33,7 +33,7 @@ public function matches(): bool */ public function getIterator(): Traversable { - yield from $this->yieldItemsByCursor(function(ResponseInterface $response) { + yield from $this->yieldItemsByCursor(function (ResponseInterface $response) { yield from $generator = $this->yieldItemsAndGetKey($response, $this->config->cursorKey); return $generator->getReturn(); diff --git a/src/Paginations/LastPageAwarePagination.php b/src/Paginations/LastPageAwarePagination.php index 94a6224..21bee16 100644 --- a/src/Paginations/LastPageAwarePagination.php +++ b/src/Paginations/LastPageAwarePagination.php @@ -29,7 +29,7 @@ public function matches(): bool */ public function getIterator(): Traversable { - yield from $this->yieldItemsUntilKey($this->config->lastPageKey, function(int $page) { + yield from $this->yieldItemsUntilKey($this->config->lastPageKey, function (int $page) { return $this->config->firstPage === 0 ? $page + 1 : $page; }); } diff --git a/src/Paginations/LinkHeaderAwarePagination.php b/src/Paginations/LinkHeaderAwarePagination.php index 3e0a4c0..57f2d40 100644 --- a/src/Paginations/LinkHeaderAwarePagination.php +++ b/src/Paginations/LinkHeaderAwarePagination.php @@ -81,7 +81,7 @@ protected function parseLinkHeader(string $linkHeader, ?string $relation = null) */ protected function yieldItemsByLastPage(int $lastPage): Generator { - yield from $this->yieldItemsUntilPage(function(ResponseInterface $response) use ($lastPage) { + yield from $this->yieldItemsUntilPage(function (ResponseInterface $response) use ($lastPage) { yield from $this->yieldItemsFrom($response); return $this->config->firstPage === 0 ? $lastPage + 1 : $lastPage; @@ -95,7 +95,7 @@ protected function yieldItemsByLastPage(int $lastPage): Generator */ protected function yieldItemsByNextLink(): Generator { - yield from $this->yieldItemsByCursor(function(ResponseInterface $response) { + yield from $this->yieldItemsByCursor(function (ResponseInterface $response) { yield from $this->yieldItemsFrom($response); return $this->parseLinkHeader($response->getHeaderLine('link'), 'next'); diff --git a/src/Paginations/TotalItemsAwarePagination.php b/src/Paginations/TotalItemsAwarePagination.php index 2241347..9c9325c 100644 --- a/src/Paginations/TotalItemsAwarePagination.php +++ b/src/Paginations/TotalItemsAwarePagination.php @@ -31,7 +31,7 @@ public function matches(): bool */ public function getIterator(): Traversable { - yield from $this->yieldItemsUntilKey($this->config->totalItemsKey, function(int $totalItems) { + yield from $this->yieldItemsUntilKey($this->config->totalItemsKey, function (int $totalItems) { return $this->itemsPerPage > 0 ? (int) ceil($totalItems / $this->itemsPerPage) : 0; }); } diff --git a/src/Services/ClientFactory.php b/src/Services/ClientFactory.php index b24bb24..142a9ff 100644 --- a/src/Services/ClientFactory.php +++ b/src/Services/ClientFactory.php @@ -5,7 +5,6 @@ namespace Cerbero\LazyJsonPages\Services; use Cerbero\LazyJsonPages\Middleware\Tap; -use Cerbero\LazyJsonPages\Services\TapCallbacks; use Closure; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; diff --git a/src/Sources/LaravelClientRequest.php b/src/Sources/LaravelClientRequest.php index ed1eb85..ab37c61 100644 --- a/src/Sources/LaravelClientRequest.php +++ b/src/Sources/LaravelClientRequest.php @@ -4,9 +4,9 @@ namespace Cerbero\LazyJsonPages\Sources; +use Illuminate\Http\Client\Request; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -use Illuminate\Http\Client\Request; /** * The Laravel HTTP client source. diff --git a/src/Sources/LaravelClientResponse.php b/src/Sources/LaravelClientResponse.php index 2490858..2e4f9c9 100644 --- a/src/Sources/LaravelClientResponse.php +++ b/src/Sources/LaravelClientResponse.php @@ -5,9 +5,9 @@ namespace Cerbero\LazyJsonPages\Sources; use Cerbero\LazyJsonPages\Exceptions\RequestNotSentException; +use Illuminate\Http\Client\Response; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -use Illuminate\Http\Client\Response; /** * The Laravel HTTP client source.