Skip to content

Commit

Permalink
minor readability (#54117)
Browse files Browse the repository at this point in the history
- use arrow functions where readability is same or better, and reduces code duplication from `use` necessity
- place methods on new line when chaining for better readability and better diffs in the future
- inline temporary variables
  • Loading branch information
browner12 authored Jan 9, 2025
1 parent d66b6c0 commit ce0c8c9
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ public function createMany(int|iterable|null $records = null)
*/
public function createManyQuietly(int|iterable|null $records = null)
{
return Model::withoutEvents(function () use ($records) {
return $this->createMany($records);
});
return Model::withoutEvents(fn () => $this->createMany($records));
}

/**
Expand Down Expand Up @@ -316,9 +314,7 @@ public function create($attributes = [], ?Model $parent = null)
*/
public function createQuietly($attributes = [], ?Model $parent = null)
{
return Model::withoutEvents(function () use ($attributes, $parent) {
return $this->create($attributes, $parent);
});
return Model::withoutEvents(fn () => $this->create($attributes, $parent));
}

/**
Expand Down Expand Up @@ -472,11 +468,10 @@ protected function getRawAttributes(?Model $parent)
*/
protected function parentResolvers()
{
$model = $this->newModel();

return $this->for->map(function (BelongsToRelationship $for) use ($model) {
return $for->recycle($this->recycle)->attributesFor($model);
})->collapse()->all();
return $this->for
->map(fn (BelongsToRelationship $for) => $for->recycle($this->recycle)->attributesFor($this->newModel()))
->collapse()
->all();
}

/**
Expand Down Expand Up @@ -524,9 +519,7 @@ public function state($state)
{
return $this->newInstance([
'states' => $this->states->concat([
is_callable($state) ? $state : function () use ($state) {
return $state;
},
is_callable($state) ? $state : fn () => $state,
]),
]);
}
Expand Down

0 comments on commit ce0c8c9

Please sign in to comment.