Skip to content

Commit 7f946ca

Browse files
authored
chore: code cleanup (#4161)
1 parent cc05a6d commit 7f946ca

File tree

141 files changed

+225
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+225
-424
lines changed

framework/core/src/Admin/Content/AdminPayload.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public function __invoke(Document $document, Request $request): void
5454
$document->payload['extensions'] = $this->extensions->getExtensions()->toArray();
5555

5656
$document->payload['displayNameDrivers'] = array_keys($this->container->make('flarum.user.display_name.supported_drivers'));
57-
$document->payload['slugDrivers'] = array_map(function ($resourceDrivers) {
58-
return array_keys($resourceDrivers);
59-
}, $this->container->make('flarum.http.slugDrivers'));
57+
$document->payload['slugDrivers'] = array_map(array_keys(...), $this->container->make('flarum.http.slugDrivers'));
6058
$document->payload['searchDrivers'] = $this->getSearchDrivers();
6159

6260
$document->payload['phpVersion'] = $this->appInfo->identifyPHPVersion();

framework/core/src/Api/Controller/UninstallExtensionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function delete(ServerRequestInterface $request): void
2727

2828
$name = Arr::get($request->getQueryParams(), 'name');
2929

30-
if ($this->extensions->getExtension($name) == null) {
30+
if ($this->extensions->getExtension($name) === null) {
3131
return;
3232
}
3333

framework/core/src/Api/Endpoint/Concerns/ExtractsListingParams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function defaultExtracts(Context $context): array
103103
return [
104104
'filter' => RequestUtil::extractFilter($context->request),
105105
'sort' => RequestUtil::extractSort($context->request, $this->defaultSort, $this->getAvailableSorts($context)),
106-
'limit' => $limit = (RequestUtil::extractLimit($context->request, $this->limit, $this->maxLimit) ?? null),
106+
'limit' => $limit = RequestUtil::extractLimit($context->request, $this->limit, $this->maxLimit),
107107
'offset' => RequestUtil::extractOffset($context->request, $limit),
108108
];
109109
}

framework/core/src/Api/Endpoint/Concerns/HasEagerLoading.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Flarum\Api\Resource\AbstractDatabaseResource;
1414
use Illuminate\Database\Eloquent\Collection;
1515
use Illuminate\Database\Eloquent\Model;
16-
use Illuminate\Database\Eloquent\Relations\Relation;
1716
use Illuminate\Support\Str;
1817
use Tobyz\JsonApiServer\Context;
1918

@@ -147,13 +146,10 @@ protected function compileSimpleEagerLoads(Context $context, array $included): a
147146

148147
protected function compileWhereEagerLoads(Context $context): array
149148
{
150-
$relations = [];
151-
152-
foreach ($this->loadRelationWhere as $name => $callable) {
153-
$relations[$name] = function ($query) use ($callable, $context) {
154-
$callable($query, $context);
155-
};
156-
}
149+
$relations = array_map(
150+
callback: fn ($callable) => fn ($query) => $callable($query, $context),
151+
array: $this->loadRelationWhere
152+
);
157153

158154
return $relations;
159155
}

framework/core/src/Api/Endpoint/Create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function setUp(): void
8989
final protected function fillDefaultValues(Context $context, array &$data): void
9090
{
9191
foreach ($context->fields($context->resource) as $field) {
92-
if (! has_value($data, $field) && ($default = $field->default)) {
92+
if (($default = $field->default) && ! has_value($data, $field)) {
9393
set_value($data, $field, $default($context->withField($field)));
9494
}
9595
}

framework/core/src/Api/Endpoint/Index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Index extends Endpoint
4343
use HasCustomHooks;
4444

4545
public Closure $paginationResolver;
46-
public ?string $defaultSort = null;
4746
protected ?Closure $query = null;
4847

4948
public function __construct(string $name)

framework/core/src/Api/Middleware/FakeHttpMethods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class FakeHttpMethods implements Middleware
1818
{
19-
const HEADER_NAME = 'x-http-method-override';
19+
public const HEADER_NAME = 'x-http-method-override';
2020

2121
public function process(Request $request, Handler $handler): Response
2222
{

framework/core/src/Api/Middleware/ThrottleApi.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function throttle(Request $request): bool
4242
// Anything else is ignored.
4343
if ($result === false) {
4444
return false;
45-
} elseif ($result === true) {
45+
}
46+
47+
if ($result === true) {
4648
$throttle = true;
4749
}
4850
}

framework/core/src/Api/Resource/AbstractDatabaseResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public function getValue(object $model, Field $field, Context $context): mixed
7474
{
7575
if ($field instanceof Relationship) {
7676
return $this->getRelationshipValue($model, $field, $context);
77-
} else {
78-
return $this->getAttributeValue($model, $field, $context);
7977
}
78+
79+
return $this->getAttributeValue($model, $field, $context);
8080
}
8181

8282
/**

framework/core/src/Api/Resource/AccessTokenResource.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ public function fields(): array
7979
{
8080
return [
8181
Schema\Str::make('token')
82-
->visible(function (AccessToken $token, Context $context) {
82+
->visible(function (#[\SensitiveParameter] AccessToken $token, Context $context) {
8383
return $context->getActor()->id === $token->user_id && ! in_array('token', $token->getHidden(), true);
8484
}),
8585
Schema\Integer::make('userId'),
8686
Schema\DateTime::make('createdAt'),
8787
Schema\DateTime::make('lastActivityAt'),
8888
Schema\Boolean::make('isCurrent')
89-
->get(function (AccessToken $token, Context $context) {
89+
->get(function (#[\SensitiveParameter] AccessToken $token, Context $context) {
9090
return $token->token === $context->request->getAttribute('session')->get('access_token');
9191
}),
9292
Schema\Boolean::make('isSessionToken')
93-
->get(function (AccessToken $token) {
93+
->get(function (#[\SensitiveParameter] AccessToken $token) {
9494
return in_array($token->type, [SessionAccessToken::$type, RememberAccessToken::$type], true);
9595
}),
9696
Schema\Str::make('title')
@@ -99,7 +99,7 @@ public function fields(): array
9999
->maxLength(255),
100100
Schema\Str::make('lastIpAddress'),
101101
Schema\Str::make('device')
102-
->get(function (AccessToken $token) {
102+
->get(function (#[\SensitiveParameter] AccessToken $token) {
103103
$agent = new Agent();
104104
$agent->setUserAgent($token->last_user_agent);
105105

0 commit comments

Comments
 (0)