Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soothe scrutinizer #308

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading