mirror of
https://github.com/flarum/core.git
synced 2025-08-05 16:07:34 +02:00
Apply fixes from StyleCI
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Endpoint\Concerns;
|
namespace Flarum\Api\Endpoint\Concerns;
|
||||||
|
|
||||||
use Flarum\Api\Schema\Concerns\FlarumField;
|
|
||||||
use Flarum\Api\Schema\Concerns\HasValidationRules;
|
use Flarum\Api\Schema\Concerns\HasValidationRules;
|
||||||
use Illuminate\Contracts\Validation\Validator;
|
use Illuminate\Contracts\Validation\Validator;
|
||||||
use Illuminate\Translation\ArrayLoader;
|
use Illuminate\Translation\ArrayLoader;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Endpoint\Concerns;
|
namespace Flarum\Api\Endpoint\Concerns;
|
||||||
|
|
||||||
use Flarum\Api\Serializer;
|
use Flarum\Api\Serializer;
|
||||||
|
@@ -212,7 +212,7 @@ class Index extends Endpoint
|
|||||||
$collection = $context->collection;
|
$collection = $context->collection;
|
||||||
|
|
||||||
if (! $collection instanceof AbstractResource) {
|
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();
|
$sorts = $collection->resolveSorts();
|
||||||
|
@@ -62,7 +62,7 @@ class JsonApi extends BaseJsonApi
|
|||||||
protected function findEndpoint(?Collection $collection): Endpoint
|
protected function findEndpoint(?Collection $collection): Endpoint
|
||||||
{
|
{
|
||||||
if (! $collection instanceof AbstractResource) {
|
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 */
|
/** @var Endpoint $endpoint */
|
||||||
@@ -161,7 +161,7 @@ class JsonApi extends BaseJsonApi
|
|||||||
$endpoint = $context->endpoint;
|
$endpoint = $context->endpoint;
|
||||||
|
|
||||||
if (! $endpoint instanceof 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(
|
$context = $context->withRequest(
|
||||||
|
@@ -11,8 +11,6 @@ namespace Flarum\Api\Resource;
|
|||||||
|
|
||||||
use Flarum\Api\Context as FlarumContext;
|
use Flarum\Api\Context as FlarumContext;
|
||||||
use Flarum\Api\Schema\Contracts\RelationAggregator;
|
use Flarum\Api\Schema\Contracts\RelationAggregator;
|
||||||
use Flarum\Foundation\DispatchEventsTrait;
|
|
||||||
use Flarum\User\User;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Concerns;
|
namespace Flarum\Api\Resource\Concerns;
|
||||||
|
|
||||||
use Flarum\Api\Context as FlarumContext;
|
use Flarum\Api\Context as FlarumContext;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api;
|
namespace Flarum\Api;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
@@ -8,6 +15,7 @@ use RuntimeException;
|
|||||||
use Tobyz\JsonApiServer\Context;
|
use Tobyz\JsonApiServer\Context;
|
||||||
use Tobyz\JsonApiServer\Resource\Resource;
|
use Tobyz\JsonApiServer\Resource\Resource;
|
||||||
use Tobyz\JsonApiServer\Schema\Field\Relationship;
|
use Tobyz\JsonApiServer\Schema\Field\Relationship;
|
||||||
|
|
||||||
use function Tobyz\JsonApiServer\has_value;
|
use function Tobyz\JsonApiServer\has_value;
|
||||||
use function Tobyz\JsonApiServer\set_value;
|
use function Tobyz\JsonApiServer\set_value;
|
||||||
|
|
||||||
@@ -60,7 +68,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer
|
|||||||
|
|
||||||
$url = "{$context->api->basePath}/$type/$id";
|
$url = "{$context->api->basePath}/$type/$id";
|
||||||
|
|
||||||
if (!isset($this->map[$key])) {
|
if (! isset($this->map[$key])) {
|
||||||
$this->map[$key] = [
|
$this->map[$key] = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
@@ -77,7 +85,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer
|
|||||||
|
|
||||||
$context = $context->withField($field)->withInclude($include[$field->name] ?? null);
|
$context = $context->withField($field)->withInclude($include[$field->name] ?? null);
|
||||||
|
|
||||||
if (!$field->isVisible($context)) {
|
if (! $field->isVisible($context)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +94,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer
|
|||||||
$this->whenResolved($value, function (mixed $value) use ($key, $field, $context) {
|
$this->whenResolved($value, function (mixed $value) use ($key, $field, $context) {
|
||||||
if (
|
if (
|
||||||
($value = $field->serializeValue($value, $context)) ||
|
($value = $field->serializeValue($value, $context)) ||
|
||||||
!$field instanceof Relationship
|
! $field instanceof Relationship
|
||||||
) {
|
) {
|
||||||
set_value($this->map[$key], $field, $value);
|
set_value($this->map[$key], $field, $value);
|
||||||
}
|
}
|
||||||
@@ -95,7 +103,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer
|
|||||||
|
|
||||||
// TODO: cache
|
// TODO: cache
|
||||||
foreach ($resource->meta() as $field) {
|
foreach ($resource->meta() as $field) {
|
||||||
if (!$field->isVisible($context)) {
|
if (! $field->isVisible($context)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +125,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer
|
|||||||
private function whenResolved($value, $callback, bool $prepend = false): void
|
private function whenResolved($value, $callback, bool $prepend = false): void
|
||||||
{
|
{
|
||||||
if ($value instanceof Closure) {
|
if ($value instanceof Closure) {
|
||||||
$callable = fn() => $this->whenResolved($value(), $callback);
|
$callable = fn () => $this->whenResolved($value(), $callback);
|
||||||
|
|
||||||
if ($prepend) {
|
if ($prepend) {
|
||||||
$this->deferred->prepend($callable);
|
$this->deferred->prepend($callable);
|
||||||
@@ -173,7 +181,7 @@ class Serializer extends \Tobyz\JsonApiServer\Serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
'No resource type defined to represent model ' . get_class($model),
|
'No resource type defined to represent model '.get_class($model),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user