Skip to content

Commit f44ef9d

Browse files
committed
replace closure with arrow function
1 parent c8e0713 commit f44ef9d

37 files changed

+182
-368
lines changed

src/Actions/Action.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,10 @@ protected function resolveField(Request $request, Field $field): void
134134
{
135135
$field->setAttribute('form', $this->getKey());
136136
$field->id($this->getKey().'-'.$field->getAttribute('id'));
137-
$field->resolveErrorsUsing(function (Request $request): MessageBag {
138-
return $this->errors($request);
139-
});
137+
$field->resolveErrorsUsing(fn(Request $request): MessageBag => $this->errors($request));
140138

141139
if ($field instanceof Relation) {
142-
$field->resolveRouteKeyNameUsing(function () use ($field): string {
143-
return Str::of($field->getRelationName())->singular()->ucfirst()->prepend($this->getKey())->value();
144-
});
140+
$field->resolveRouteKeyNameUsing(fn(): string => Str::of($field->getRelationName())->singular()->ucfirst()->prepend($this->getKey())->value());
145141
}
146142
}
147143

src/Actions/Actions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function visible(string|array $context): static
4444
*/
4545
public function standalone(bool $value = true): static
4646
{
47-
return $this->filter(static function (Action $action) use ($value): bool {
48-
return $value ? $action->isStandalone() : ! $action->isStandalone();
49-
});
47+
return $this->filter(static fn(Action $action): bool => $value ? $action->isStandalone() : ! $action->isStandalone());
5048
}
5149

5250
/**

src/Actions/SendVerificationNotification.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class SendVerificationNotification extends Action
1313
*/
1414
public function handle(Request $request, Collection $models): void
1515
{
16-
$models->reject(static function (User $user): bool {
17-
return $user->hasVerifiedEmail();
18-
})->each(static function (User $user): void {
16+
$models->reject(static fn(User $user): bool => $user->hasVerifiedEmail())->each(static function (User $user): void {
1917
$user->sendEmailVerificationNotification();
2018
});
2119
}

src/Fields/BelongsToMany.php

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,21 @@ public function getRelation(Model $model): EloquentRelation
6767
public function fields(Request $request): array
6868
{
6969
return [
70-
BelongsTo::make($this->getRelatedName(), 'related', static function (Pivot $model): BelongsToRelation {
71-
return $model->belongsTo(
72-
$model->getRelation('related')::class,
73-
$model->getRelatedKey(),
74-
$model->getForeignKey(),
75-
'related'
76-
)->withDefault();
77-
})->withRelatableQuery(function (Request $request, Builder $query, Pivot $model): Builder {
78-
return $this->resolveRelatableQuery($request, $model->pivotParent)
79-
->unless($this->allowDuplicateRelations, function (Builder $query) use ($model): Builder {
80-
return $query->whereNotIn(
81-
$query->getModel()->getQualifiedKeyName(),
82-
$this->getRelation($model->pivotParent)->select($query->getModel()->getQualifiedKeyName())
83-
);
84-
});
85-
})->hydrate(function (Request $request, Pivot $model, mixed $value): void {
70+
BelongsTo::make($this->getRelatedName(), 'related', static fn(Pivot $model): BelongsToRelation => $model->belongsTo(
71+
$model->getRelation('related')::class,
72+
$model->getRelatedKey(),
73+
$model->getForeignKey(),
74+
'related'
75+
)->withDefault())->withRelatableQuery(fn(Request $request, Builder $query, Pivot $model): Builder => $this->resolveRelatableQuery($request, $model->pivotParent)
76+
->unless($this->allowDuplicateRelations, fn(Builder $query): Builder => $query->whereNotIn(
77+
$query->getModel()->getQualifiedKeyName(),
78+
$this->getRelation($model->pivotParent)->select($query->getModel()->getQualifiedKeyName())
79+
)))->hydrate(function (Request $request, Pivot $model, mixed $value): void {
8680
$model->setAttribute(
8781
$this->getRelation($model->pivotParent)->getRelatedPivotKeyName(),
8882
$value
8983
);
90-
})->display(function (Model $model): ?string {
91-
return $this->resolveDisplay($model);
92-
}),
84+
})->display(fn(Model $model): ?string => $this->resolveDisplay($model)),
9385
];
9486
}
9587

@@ -115,9 +107,7 @@ protected function resolveField(Request $request, Field $field): void
115107
}
116108

117109
if ($field instanceof Relation) {
118-
$field->resolveRouteKeyNameUsing(function () use ($field): string {
119-
return Str::of($field->getRelationName())->singular()->ucfirst()->prepend($this->getRouteKeyName())->value();
120-
});
110+
$field->resolveRouteKeyNameUsing(fn(): string => Str::of($field->getRelationName())->singular()->ucfirst()->prepend($this->getRouteKeyName())->value());
121111
}
122112

123113
parent::resolveField($request, $field);
@@ -146,9 +136,7 @@ public function withPivotFields(Closure $callback): static
146136
$field->setModelAttribute($attribute)
147137
->name($attribute)
148138
->id($attribute)
149-
->value(function () use ($model, $related, $key): mixed {
150-
return $related->getRelation($this->getRelation($model)->getPivotAccessor())->getAttribute($key);
151-
});
139+
->value(fn(): mixed => $related->getRelation($this->getRelation($model)->getPivotAccessor())->getAttribute($key));
152140
});
153141

154142
return $fields;
@@ -174,9 +162,7 @@ public function mergePivotValues(array $value): array
174162
{
175163
$value = array_is_list($value) ? array_fill_keys($value, []) : $value;
176164

177-
return array_map(function (array $pivot): array {
178-
return array_merge($this->pivotValues, $pivot);
179-
}, $value);
165+
return array_map(fn(array $pivot): array => array_merge($this->pivotValues, $pivot), $value);
180166
}
181167

182168
/**

src/Fields/Boolean.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ public function resolveValue(Request $request, Model $model): bool
6060
public function resolveFormat(Request $request, Model $model): ?string
6161
{
6262
if (is_null($this->formatResolver)) {
63-
$this->formatResolver = static function (Request $request, Model $model, ?bool $value): string {
64-
return sprintf(
65-
'<span class="status %s">%s</span>',
66-
$value ? 'status--success' : 'status--danger',
67-
$value ? __('Yes') : __('No')
68-
);
69-
};
63+
$this->formatResolver = static fn(Request $request, Model $model, ?bool $value): string => sprintf(
64+
'<span class="status %s">%s</span>',
65+
$value ? 'status--success' : 'status--danger',
66+
$value ? __('Yes') : __('No')
67+
);
7068
}
7169

7270
return parent::resolveFormat($request, $model);

src/Fields/Date.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public function getValue(Model $model): mixed
132132
public function resolveFormat(Request $request, Model $model): ?string
133133
{
134134
if (is_null($this->formatResolver)) {
135-
$this->formatResolver = function (Request $request, Model $model, mixed $value): ?string {
136-
return is_null($value) ? $value : $value->format($this->format);
137-
};
135+
$this->formatResolver = fn(Request $request, Model $model, mixed $value): ?string => is_null($value) ? $value : $value->format($this->format);
138136
}
139137

140138
return parent::resolveFormat($request, $model);

src/Fields/Dropdown.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,14 @@ public function toInput(Request $request, Model $model): array
3333
$data = parent::toInput($request, $model);
3434

3535
return array_merge($data, [
36-
'options' => array_map(static function (array $option): array {
37-
return array_merge($option, [
38-
'html' => View::make('root::fields.dropdown-option', $option)->render(),
39-
]);
40-
}, $data['options']),
36+
'options' => array_map(static fn(array $option): array => array_merge($option, [
37+
'html' => View::make('root::fields.dropdown-option', $option)->render(),
38+
]), $data['options']),
4139
'selection' => Collection::make($data['options'])
4240
->filter(fn (array $option): bool => $option['selected'] ?? false)
43-
->map(static function (array $option): array {
44-
return array_merge($option, [
45-
'html' => View::make('root::fields.dropdown-option', $option)->render(),
46-
]);
47-
})
41+
->map(static fn(array $option): array => array_merge($option, [
42+
'html' => View::make('root::fields.dropdown-option', $option)->render(),
43+
]))
4844
->values()
4945
->all(),
5046
'config' => [

src/Fields/Editor.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,19 @@ protected function newMediaField(): Media
119119
{
120120
public function __construct(string $modelAttribute)
121121
{
122-
parent::__construct(__('Media'), $modelAttribute.'-media', static function (): MorphToMany {
123-
return new MorphToMany(
124-
Medium::proxy()->newQuery(),
125-
new class extends Model
126-
{
127-
//
128-
},
129-
'media',
130-
'root_mediables',
131-
'medium_id',
132-
'_model_id',
133-
'id',
134-
'id'
135-
);
136-
});
122+
parent::__construct(__('Media'), $modelAttribute.'-media', static fn(): MorphToMany => new MorphToMany(
123+
Medium::proxy()->newQuery(),
124+
new class extends Model
125+
{
126+
//
127+
},
128+
'media',
129+
'root_mediables',
130+
'medium_id',
131+
'_model_id',
132+
'id',
133+
'id'
134+
));
137135

138136
$this->template = 'root::fields.editor.media';
139137

src/Fields/Field.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,7 @@ public function toValidate(Request $request, Model $model): array
661661
$key = $model->exists ? 'update' : 'create';
662662

663663
$rules = array_map(
664-
static function (array|Closure $rule) use ($request, $model): array {
665-
return is_array($rule) ? $rule : call_user_func_array($rule, [$request, $model]);
666-
},
664+
static fn(array|Closure $rule): array => is_array($rule) ? $rule : call_user_func_array($rule, [$request, $model]),
667665
Arr::only($this->rules, array_unique(['*', $key]))
668666
);
669667

src/Fields/Fields.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,33 @@ public function sortable(): static
7272
*/
7373
public function relation(): static
7474
{
75-
return $this->filter(static function (Field $field): bool {
76-
return $field instanceof Relation;
77-
});
75+
return $this->filter(static fn(Field $field): bool => $field instanceof Relation);
7876
}
7977

8078
/**
8179
* Filter the translatable fields.
8280
*/
8381
public function translatable(): static
8482
{
85-
return $this->filter(static function (Field $field): bool {
86-
return $field->isTranslatable();
87-
});
83+
return $this->filter(static fn(Field $field): bool => $field->isTranslatable());
8884
}
8985

9086
/**
9187
* Filter the subresource fields.
9288
*/
9389
public function subResource(bool $value = true): static
9490
{
95-
return $this->filter(static function (Field $field) use ($value): bool {
96-
return $value
97-
? $field instanceof Relation && $field->isSubResource()
98-
: ! $field instanceof Relation || ! $field->isSubResource();
99-
});
91+
return $this->filter(static fn(Field $field): bool => $value
92+
? $field instanceof Relation && $field->isSubResource()
93+
: ! $field instanceof Relation || ! $field->isSubResource());
10094
}
10195

10296
/**
10397
* Map the fields to validate.
10498
*/
10599
public function mapToValidate(Request $request, Model $model): array
106100
{
107-
return $this->reduce(static function (array $rules, Field $field) use ($request, $model): array {
108-
return array_merge_recursive($rules, $field->toValidate($request, $model));
109-
}, []);
101+
return $this->reduce(static fn(array $rules, Field $field): array => array_merge_recursive($rules, $field->toValidate($request, $model)), []);
110102
}
111103

112104
/**

0 commit comments

Comments
 (0)