From 7504e313992af9b18e1d42a2062e6f95e0081d6d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 10 May 2024 19:30:06 +0000 Subject: [PATCH] Apply fixes from StyleCI --- .../Concerns/SavesAndValidatesData.php | 1 - .../Api/Endpoint/Concerns/ShowsResources.php | 7 +++++++ framework/core/src/Api/Endpoint/Index.php | 2 +- framework/core/src/Api/JsonApi.php | 4 ++-- .../Api/Resource/AbstractDatabaseResource.php | 2 -- .../src/Api/Resource/Concerns/HasHooks.php | 7 +++++++ framework/core/src/Api/Serializer.php | 20 +++++++++++++------ 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/framework/core/src/Api/Endpoint/Concerns/SavesAndValidatesData.php b/framework/core/src/Api/Endpoint/Concerns/SavesAndValidatesData.php index 2fa6a8f7c..dd8767b81 100644 --- a/framework/core/src/Api/Endpoint/Concerns/SavesAndValidatesData.php +++ b/framework/core/src/Api/Endpoint/Concerns/SavesAndValidatesData.php @@ -9,7 +9,6 @@ namespace Flarum\Api\Endpoint\Concerns; -use Flarum\Api\Schema\Concerns\FlarumField; use Flarum\Api\Schema\Concerns\HasValidationRules; use Illuminate\Contracts\Validation\Validator; use Illuminate\Translation\ArrayLoader; diff --git a/framework/core/src/Api/Endpoint/Concerns/ShowsResources.php b/framework/core/src/Api/Endpoint/Concerns/ShowsResources.php index 637c5d7cd..1ed9695f8 100644 --- a/framework/core/src/Api/Endpoint/Concerns/ShowsResources.php +++ b/framework/core/src/Api/Endpoint/Concerns/ShowsResources.php @@ -1,5 +1,12 @@ collection; if (! $collection instanceof AbstractResource) { - throw new RuntimeException('The collection ' . $collection::class . ' must extend ' . AbstractResource::class); + throw new RuntimeException('The collection '.$collection::class.' must extend '.AbstractResource::class); } $sorts = $collection->resolveSorts(); diff --git a/framework/core/src/Api/JsonApi.php b/framework/core/src/Api/JsonApi.php index 357adc5da..f54e8638a 100644 --- a/framework/core/src/Api/JsonApi.php +++ b/framework/core/src/Api/JsonApi.php @@ -62,7 +62,7 @@ class JsonApi extends BaseJsonApi protected function findEndpoint(?Collection $collection): Endpoint { if (! $collection instanceof AbstractResource) { - throw new RuntimeException('Resource ' . $collection::class . ' must extend ' . AbstractResource::class); + throw new RuntimeException('Resource '.$collection::class.' must extend '.AbstractResource::class); } /** @var Endpoint $endpoint */ @@ -161,7 +161,7 @@ class JsonApi extends BaseJsonApi $endpoint = $context->endpoint; if (! $endpoint instanceof Endpoint) { - throw new RuntimeException('The endpoint ' . $endpoint::class . ' must extend ' . Endpoint::class); + throw new RuntimeException('The endpoint '.$endpoint::class.' must extend '.Endpoint::class); } $context = $context->withRequest( diff --git a/framework/core/src/Api/Resource/AbstractDatabaseResource.php b/framework/core/src/Api/Resource/AbstractDatabaseResource.php index e54e4918b..24cb2f212 100644 --- a/framework/core/src/Api/Resource/AbstractDatabaseResource.php +++ b/framework/core/src/Api/Resource/AbstractDatabaseResource.php @@ -11,8 +11,6 @@ namespace Flarum\Api\Resource; use Flarum\Api\Context as FlarumContext; use Flarum\Api\Schema\Contracts\RelationAggregator; -use Flarum\Foundation\DispatchEventsTrait; -use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; diff --git a/framework/core/src/Api/Resource/Concerns/HasHooks.php b/framework/core/src/Api/Resource/Concerns/HasHooks.php index aa98cb9d2..056eea1dc 100644 --- a/framework/core/src/Api/Resource/Concerns/HasHooks.php +++ b/framework/core/src/Api/Resource/Concerns/HasHooks.php @@ -1,5 +1,12 @@ api->basePath}/$type/$id"; - if (!isset($this->map[$key])) { + if (! isset($this->map[$key])) { $this->map[$key] = [ 'type' => $type, 'id' => $id, @@ -77,7 +85,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer $context = $context->withField($field)->withInclude($include[$field->name] ?? null); - if (!$field->isVisible($context)) { + if (! $field->isVisible($context)) { continue; } @@ -86,7 +94,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer $this->whenResolved($value, function (mixed $value) use ($key, $field, $context) { if ( ($value = $field->serializeValue($value, $context)) || - !$field instanceof Relationship + ! $field instanceof Relationship ) { set_value($this->map[$key], $field, $value); } @@ -95,7 +103,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer // TODO: cache foreach ($resource->meta() as $field) { - if (!$field->isVisible($context)) { + if (! $field->isVisible($context)) { continue; } @@ -117,7 +125,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer private function whenResolved($value, $callback, bool $prepend = false): void { if ($value instanceof Closure) { - $callable = fn() => $this->whenResolved($value(), $callback); + $callable = fn () => $this->whenResolved($value(), $callback); if ($prepend) { $this->deferred->prepend($callable); @@ -173,7 +181,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer } throw new RuntimeException( - 'No resource type defined to represent model ' . get_class($model), + 'No resource type defined to represent model '.get_class($model), ); }