Skip to content

Commit

Permalink
[11.x] Add Laravel Pint (#53835)
Browse files Browse the repository at this point in the history
* install Pint with custom configuration

- use an empty preset
- set 1 explicit rule
- ignore `/tests` (for now)

* run Pint

this rule ensures all chained methods on a new line are indented exactly once.

this avoids arbitrarily aligning with some character or pattern in the first line line, while still giving us the readability of aligned subsequent lines.

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
browner12 and taylorotwell authored Jan 22, 2025
1 parent be60158 commit 22ceb4a
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public function cursor($query, $bindings = [], $useReadPdo = true)
// mode and prepare the bindings for the query. Once that's done we will be
// ready to execute the query against the database and return the cursor.
$statement = $this->prepared($this->getPdoForSelect($useReadPdo)
->prepare($query));
->prepare($query));

$this->bindValues(
$statement, $this->prepareBindings($bindings)
Expand Down
8 changes: 4 additions & 4 deletions Console/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ protected function schemaState(Connection $connection)
$migrationTable = is_array($migrations) ? ($migrations['table'] ?? 'migrations') : $migrations;

return $connection->getSchemaState()
->withMigrationTable($migrationTable)
->handleOutputUsing(function ($type, $buffer) {
$this->output->write($buffer);
});
->withMigrationTable($migrationTable)
->handleOutputUsing(function ($type, $buffer) {
$this->output->write($buffer);
});
}

/**
Expand Down
20 changes: 10 additions & 10 deletions Console/Migrations/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ public function handle()
protected function getStatusFor(array $ran, array $batches)
{
return (new Collection($this->getAllMigrationFiles()))
->map(function ($migration) use ($ran, $batches) {
$migrationName = $this->migrator->getMigrationName($migration);
->map(function ($migration) use ($ran, $batches) {
$migrationName = $this->migrator->getMigrationName($migration);

$status = in_array($migrationName, $ran)
? '<fg=green;options=bold>Ran</>'
: '<fg=yellow;options=bold>Pending</>';
$status = in_array($migrationName, $ran)
? '<fg=green;options=bold>Ran</>'
: '<fg=yellow;options=bold>Pending</>';

if (in_array($migrationName, $ran)) {
$status = '['.$batches[$migrationName].'] '.$status;
}
if (in_array($migrationName, $ran)) {
$status = '['.$batches[$migrationName].'] '.$status;
}

return [$migrationName, $status];
});
return [$migrationName, $status];
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Console/Seeds/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ protected function getSeeder()
}

return $this->laravel->make($class)
->setContainer($this->laravel)
->setCommand($this);
->setContainer($this->laravel)
->setCommand($this);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions Console/WipeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function handle()
protected function dropAllTables($database)
{
$this->laravel['db']->connection($database)
->getSchemaBuilder()
->dropAllTables();
->getSchemaBuilder()
->dropAllTables();
}

/**
Expand All @@ -82,8 +82,8 @@ protected function dropAllTables($database)
protected function dropAllViews($database)
{
$this->laravel['db']->connection($database)
->getSchemaBuilder()
->dropAllViews();
->getSchemaBuilder()
->dropAllViews();
}

/**
Expand All @@ -95,8 +95,8 @@ protected function dropAllViews($database)
protected function dropAllTypes($database)
{
$this->laravel['db']->connection($database)
->getSchemaBuilder()
->dropAllTypes();
->getSchemaBuilder()
->dropAllTypes();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function configuration($name)
}

return (new ConfigurationUrlParser)
->parseConfiguration($config);
->parseConfiguration($config);
}

/**
Expand Down Expand Up @@ -374,8 +374,8 @@ protected function refreshPdoConnections($name)
);

return $this->connections[$name]
->setPdo($fresh->getRawPdo())
->setReadPdo($fresh->getRawReadPdo());
->setPdo($fresh->getRawPdo())
->setReadPdo($fresh->getRawReadPdo());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Eloquent/Concerns/GuardsAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ protected function isGuardableColumn($key)

if (! isset(static::$guardableColumns[get_class($this)])) {
$columns = $this->getConnection()
->getSchemaBuilder()
->getColumnListing($this->getTable());
->getSchemaBuilder()
->getColumnListing($this->getTable());

if (empty($columns)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion Eloquent/Concerns/QueriesRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function hasMorph($relation, $types, $operator = '>=', $count = 1, $boole
}

$query->where($this->qualifyColumn($relation->getMorphType()), '=', (new $type)->getMorphClass())
->whereHas($belongsTo, $callback, $operator, $count);
->whereHas($belongsTo, $callback, $operator, $count);
});
}
}, null, null, $boolean);
Expand Down
4 changes: 2 additions & 2 deletions Eloquent/Factories/HasFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public static function factory($count = null, $state = [])
$factory = static::newFactory() ?? Factory::factoryForModel(static::class);

return $factory
->count(is_numeric($count) ? $count : null)
->state(is_callable($count) || is_array($count) ? $count : $state);
->count(is_numeric($count) ? $count : null)
->state(is_callable($count) || is_array($count) ? $count : $state);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Eloquent/Relations/Concerns/ComparesRelatedModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function is($model)

if ($match && $this instanceof SupportsPartialRelations && $this->isOneOfMany()) {
return $this->query
->whereKey($model->getKey())
->exists();
->whereKey($model->getKey())
->exists();
}

return $match;
Expand Down
8 changes: 4 additions & 4 deletions Eloquent/Relations/Concerns/InteractsWithPivotTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function sync($ids, $detaching = true)
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
$current = $this->getCurrentlyAttachedPivots()
->pluck($this->relatedPivotKey)->all();
->pluck($this->relatedPivotKey)->all();

$records = $this->formatRecordsList($this->parseIds($ids));

Expand Down Expand Up @@ -240,9 +240,9 @@ public function updateExistingPivot($id, array $attributes, $touch = true)
protected function updateExistingPivotUsingCustomClass($id, array $attributes, $touch)
{
$pivot = $this->getCurrentlyAttachedPivots()
->where($this->foreignPivotKey, $this->parent->{$this->parentKey})
->where($this->relatedPivotKey, $this->parseId($id))
->first();
->where($this->foreignPivotKey, $this->parent->{$this->parentKey})
->where($this->relatedPivotKey, $this->parseId($id))
->first();

$updated = $pivot ? $pivot->fill($attributes)->isDirty() : false;

Expand Down
10 changes: 5 additions & 5 deletions Eloquent/Relations/MorphPivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ public function newQueryForRestoration($ids)
$segments = explode(':', $ids);

return $this->newQueryWithoutScopes()
->where($segments[0], $segments[1])
->where($segments[2], $segments[3])
->where($segments[4], $segments[5]);
->where($segments[0], $segments[1])
->where($segments[2], $segments[3])
->where($segments[4], $segments[5]);
}

/**
Expand All @@ -174,8 +174,8 @@ protected function newQueryForCollectionRestoration(array $ids)

$query->orWhere(function ($query) use ($segments) {
return $query->where($segments[0], $segments[1])
->where($segments[2], $segments[3])
->where($segments[4], $segments[5]);
->where($segments[2], $segments[3])
->where($segments[4], $segments[5]);
});
}

Expand Down
16 changes: 8 additions & 8 deletions Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ protected function getResultsByType($type)
$ownerKey = $this->ownerKey ?? $instance->getKeyName();

$query = $this->replayMacros($instance->newQuery())
->mergeConstraintsFrom($this->getQuery())
->with(array_merge(
$this->getQuery()->getEagerLoads(),
(array) ($this->morphableEagerLoads[get_class($instance)] ?? [])
))
->withCount(
(array) ($this->morphableEagerLoadCounts[get_class($instance)] ?? [])
);
->mergeConstraintsFrom($this->getQuery())
->with(array_merge(
$this->getQuery()->getEagerLoads(),
(array) ($this->morphableEagerLoads[get_class($instance)] ?? [])
))
->withCount(
(array) ($this->morphableEagerLoadCounts[get_class($instance)] ?? [])
);

if ($callback = ($this->morphableConstraints[get_class($instance)] ?? null)) {
$callback($query);
Expand Down
8 changes: 4 additions & 4 deletions Eloquent/Relations/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function getCurrentlyAttachedPivots()
return parent::getCurrentlyAttachedPivots()->map(function ($record) {
return $record instanceof MorphPivot
? $record->setMorphType($this->morphType)
->setMorphClass($this->morphClass)
->setMorphClass($this->morphClass)
: $record;
});
}
Expand Down Expand Up @@ -161,9 +161,9 @@ public function newPivot(array $attributes = [], $exists = false)
: MorphPivot::fromAttributes($this->parent, $attributes, $this->table, $exists);

$pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey)
->setRelatedModel($this->related)
->setMorphType($this->morphType)
->setMorphClass($this->morphClass);
->setRelatedModel($this->related)
->setMorphType($this->morphType)
->setMorphClass($this->morphClass);

return $pivot;
}
Expand Down
16 changes: 8 additions & 8 deletions Migrations/DatabaseMigrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function __construct(Resolver $resolver, $table)
public function getRan()
{
return $this->table()
->orderBy('batch', 'asc')
->orderBy('migration', 'asc')
->pluck('migration')->all();
->orderBy('batch', 'asc')
->orderBy('migration', 'asc')
->pluck('migration')->all();
}

/**
Expand All @@ -64,8 +64,8 @@ public function getMigrations($steps)
$query = $this->table()->where('batch', '>=', '1');

return $query->orderBy('batch', 'desc')
->orderBy('migration', 'desc')
->take($steps)->get()->all();
->orderBy('migration', 'desc')
->take($steps)->get()->all();
}

/**
Expand Down Expand Up @@ -103,9 +103,9 @@ public function getLast()
public function getMigrationBatches()
{
return $this->table()
->orderBy('batch', 'asc')
->orderBy('migration', 'asc')
->pluck('batch', 'migration')->all();
->orderBy('batch', 'asc')
->orderBy('migration', 'asc')
->pluck('batch', 'migration')->all();
}

/**
Expand Down
38 changes: 19 additions & 19 deletions Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2820,7 +2820,7 @@ public function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')
}

return $this->orderBy($column, 'desc')
->limit($perPage);
->limit($perPage);
}

/**
Expand All @@ -2840,7 +2840,7 @@ public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
}

return $this->orderBy($column, 'asc')
->limit($perPage);
->limit($perPage);
}

/**
Expand Down Expand Up @@ -2873,10 +2873,10 @@ public function reorder($column = null, $direction = 'asc')
protected function removeExistingOrdersFor($column)
{
return (new Collection($this->orders))
->reject(function ($order) use ($column) {
return isset($order['column'])
? $order['column'] === $column : false;
})->values()->all();
->reject(function ($order) use ($column) {
return isset($order['column'])
? $order['column'] === $column : false;
})->values()->all();
}

/**
Expand Down Expand Up @@ -3307,9 +3307,9 @@ protected function runPaginationCountQuery($columns = ['*'])
$without = $this->unions ? ['unionOrders', 'unionLimit', 'unionOffset'] : ['columns', 'orders', 'limit', 'offset'];

return $this->cloneWithout($without)
->cloneWithoutBindings($this->unions ? ['unionOrder'] : ['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
->cloneWithoutBindings($this->unions ? ['unionOrder'] : ['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
}

/**
Expand All @@ -3320,7 +3320,7 @@ protected function runPaginationCountQuery($columns = ['*'])
protected function cloneForPaginationCount()
{
return $this->cloneWithout(['orders', 'limit', 'offset'])
->cloneWithoutBindings(['order']);
->cloneWithoutBindings(['order']);
}

/**
Expand Down Expand Up @@ -3628,9 +3628,9 @@ public function average($column)
public function aggregate($function, $columns = ['*'])
{
$results = $this->cloneWithout($this->unions || $this->havings ? [] : ['columns'])
->cloneWithoutBindings($this->unions || $this->havings ? [] : ['select'])
->setAggregate($function, $columns)
->get($columns);
->cloneWithoutBindings($this->unions || $this->havings ? [] : ['select'])
->setAggregate($function, $columns)
->get($columns);

if (! $results->isEmpty()) {
return array_change_key_case((array) $results[0])['aggregate'];
Expand Down Expand Up @@ -4243,12 +4243,12 @@ public function mergeBindings(self $query)
public function cleanBindings(array $bindings)
{
return (new Collection($bindings))
->reject(function ($binding) {
return $binding instanceof ExpressionContract;
})
->map([$this, 'castBinding'])
->values()
->all();
->reject(function ($binding) {
return $binding instanceof ExpressionContract;
})
->map([$this, 'castBinding'])
->values()
->all();
}

/**
Expand Down

0 comments on commit 22ceb4a

Please sign in to comment.