Skip to content

Commit

Permalink
Merge pull request #308 from bearsunday/soothe-scrutinizer
Browse files Browse the repository at this point in the history
Soothe scrutinizer
  • Loading branch information
koriym authored Oct 22, 2024
2 parents 9d90024 + 48b846c commit 75031f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/ClassParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
use function preg_replace;
use function strtolower;

use const PHP_VERSION_ID;

final class ClassParam implements ParamInterface
{
private readonly string $type;
Expand Down Expand Up @@ -64,7 +62,7 @@ public function __invoke(string $varName, array $query, InjectorInterface $injec
assert(class_exists($this->type));
$refClass = (new ReflectionClass($this->type));

if (PHP_VERSION_ID >= 80100 && $refClass->isEnum()) {
if ($refClass->isEnum()) {
return $this->enum($this->type, $props, $varName);
}

Expand Down
21 changes: 14 additions & 7 deletions src/EmbedInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,16 @@ private function embedResource(array $embeds, ResourceObject $ro, array $query):
$uri = uri_template($templateUri, $query);
/** @var Request $request */ // phpcs:ignore SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion
$request = $this->resource->get->uri($uri);
if ($ro->body === null) {
$ro->body = [];
}

if (! is_array($ro->body)) {
throw new LinkException($embed->rel); // @codeCoverageIgnore
}
$this->prepareBody($ro, $embed);

if ($embed->rel === self::SELF_LINK) {
$this->linkSelf($request, $ro);

continue;
}

assert(is_array($ro->body));

$ro->body[$embed->rel] = clone $request;
} catch (BadRequestException $e) {
// wrap ResourceNotFound or Uri exception
Expand All @@ -97,6 +93,17 @@ private function getFullUri(string $uri, ResourceObject $ro): string
return $uri;
}

public function prepareBody(ResourceObject $ro, Embed $embed): void
{
if ($ro->body === null) {
$ro->body = [];
}

if (! is_array($ro->body)) {
throw new LinkException($embed->rel); // @codeCoverageIgnore
}
}

/** @return array<string, mixed> */
private function getArgsByInvocation(MethodInvocation $invocation): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/HttpRequestCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
) {
}

/** @inheritdoc */
/** @inheritDoc */
public function request(string $method, string $uri, array $query): array
{
$body = http_build_query($query);
Expand Down

0 comments on commit 75031f0

Please sign in to comment.