Skip to content

Commit

Permalink
Fix PHPStan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xHeaven committed Dec 16, 2024
1 parent be22781 commit 255905f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/GraphQLClientMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private function makeQueryRequest(string $query, bool $withExtensions = false, b
if ($this->tries < config('shopify-graphql.throttle_max_tries')) {
$this->tries++;

// @phpstan-ignore method.nonObject
$this->rateLimitService->waitIfNecessary((float)$this->requestedQueryCost);

return $this->makeQueryRequest($query, $withExtensions, $detailedCost);
Expand Down Expand Up @@ -192,6 +193,7 @@ private function makeMutationRequest(string $query, array $variables, bool $with
if ($this->tries < config('shopify-graphql.throttle_max_tries')) {
$this->tries++;

// @phpstan-ignore method.nonObject
$this->rateLimitService->waitIfNecessary((float)$this->requestedQueryCost);

return $this->makeMutationRequest($query, $variables, $withExtensions, $detailedCost);
Expand Down Expand Up @@ -278,6 +280,8 @@ private function updateRateLimitInfo(array $response): void
'currentlyAvailable' => $this->currentlyAvailable,
'restoreRate' => $this->restoreRate,
];

// @phpstan-ignore method.nonObject
$this->rateLimitService->updateRateLimitInfo($rateLimitData);
}

Expand Down
9 changes: 4 additions & 5 deletions src/Services/QueryTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GraphQL\Language\AST\ArgumentNode;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeList;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Language\Parser;
Expand Down Expand Up @@ -55,10 +56,12 @@ public static function transformQueryWithPagination(string $queryString, array $

private static function applyPaginationArguments(NodeList $arguments, array $paginationArgs): NodeList
{
/** @var Node[] $argsArray */
$argsArray = iterator_to_array($arguments);
$argsMap = [];

foreach ($argsArray as $argNode) {
// @phpstan-ignore property.notFound
$argsMap[$argNode->name->value] = $argNode;
}

Expand Down Expand Up @@ -86,10 +89,6 @@ private static function phpValueToGraphQLLiteral(mixed $value): string
return (string)$value;
}

if (is_string($value)) {
return json_encode($value, JSON_UNESCAPED_UNICODE);
}

if (is_array($value)) {
if (Arr::isAssoc($value)) {
$fields = [];
Expand All @@ -105,6 +104,6 @@ private static function phpValueToGraphQLLiteral(mixed $value): string
return '[' . implode(', ', $items) . ']';
}

return json_encode((string)$value, JSON_UNESCAPED_UNICODE);
return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
}
}

0 comments on commit 255905f

Please sign in to comment.