From 22ceb4a021399522a7785909f9b4fdd53b25d75a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 22 Jan 2025 15:19:28 -0600 Subject: [PATCH] [11.x] Add Laravel Pint (#53835) * 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 --- Connection.php | 2 +- Console/DumpCommand.php | 8 ++-- Console/Migrations/StatusCommand.php | 20 +++++----- Console/Seeds/SeedCommand.php | 4 +- Console/WipeCommand.php | 12 +++--- DatabaseManager.php | 6 +-- Eloquent/Concerns/GuardsAttributes.php | 4 +- Eloquent/Concerns/QueriesRelationships.php | 2 +- Eloquent/Factories/HasFactory.php | 4 +- .../Concerns/ComparesRelatedModels.php | 4 +- .../Concerns/InteractsWithPivotTable.php | 8 ++-- Eloquent/Relations/MorphPivot.php | 10 ++--- Eloquent/Relations/MorphTo.php | 16 ++++---- Eloquent/Relations/MorphToMany.php | 8 ++-- Migrations/DatabaseMigrationRepository.php | 16 ++++---- Query/Builder.php | 38 +++++++++---------- 16 files changed, 81 insertions(+), 81 deletions(-) diff --git a/Connection.php b/Connection.php index 692dfdee2..64f2eb25b 100755 --- a/Connection.php +++ b/Connection.php @@ -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) diff --git a/Console/DumpCommand.php b/Console/DumpCommand.php index 64148e90f..b27d6c66a 100644 --- a/Console/DumpCommand.php +++ b/Console/DumpCommand.php @@ -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); + }); } /** diff --git a/Console/Migrations/StatusCommand.php b/Console/Migrations/StatusCommand.php index 191983288..378c4a720 100644 --- a/Console/Migrations/StatusCommand.php +++ b/Console/Migrations/StatusCommand.php @@ -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) - ? 'Ran' - : 'Pending'; + $status = in_array($migrationName, $ran) + ? 'Ran' + : '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]; + }); } /** diff --git a/Console/Seeds/SeedCommand.php b/Console/Seeds/SeedCommand.php index 0d4dbd5ad..4ce2b0213 100644 --- a/Console/Seeds/SeedCommand.php +++ b/Console/Seeds/SeedCommand.php @@ -96,8 +96,8 @@ protected function getSeeder() } return $this->laravel->make($class) - ->setContainer($this->laravel) - ->setCommand($this); + ->setContainer($this->laravel) + ->setCommand($this); } /** diff --git a/Console/WipeCommand.php b/Console/WipeCommand.php index f756dd121..754c9eea8 100644 --- a/Console/WipeCommand.php +++ b/Console/WipeCommand.php @@ -69,8 +69,8 @@ public function handle() protected function dropAllTables($database) { $this->laravel['db']->connection($database) - ->getSchemaBuilder() - ->dropAllTables(); + ->getSchemaBuilder() + ->dropAllTables(); } /** @@ -82,8 +82,8 @@ protected function dropAllTables($database) protected function dropAllViews($database) { $this->laravel['db']->connection($database) - ->getSchemaBuilder() - ->dropAllViews(); + ->getSchemaBuilder() + ->dropAllViews(); } /** @@ -95,8 +95,8 @@ protected function dropAllViews($database) protected function dropAllTypes($database) { $this->laravel['db']->connection($database) - ->getSchemaBuilder() - ->dropAllTypes(); + ->getSchemaBuilder() + ->dropAllTypes(); } /** diff --git a/DatabaseManager.php b/DatabaseManager.php index 6f8867c4e..34ba2cc01 100755 --- a/DatabaseManager.php +++ b/DatabaseManager.php @@ -228,7 +228,7 @@ protected function configuration($name) } return (new ConfigurationUrlParser) - ->parseConfiguration($config); + ->parseConfiguration($config); } /** @@ -374,8 +374,8 @@ protected function refreshPdoConnections($name) ); return $this->connections[$name] - ->setPdo($fresh->getRawPdo()) - ->setReadPdo($fresh->getRawReadPdo()); + ->setPdo($fresh->getRawPdo()) + ->setReadPdo($fresh->getRawReadPdo()); } /** diff --git a/Eloquent/Concerns/GuardsAttributes.php b/Eloquent/Concerns/GuardsAttributes.php index a81337729..67229b4a0 100644 --- a/Eloquent/Concerns/GuardsAttributes.php +++ b/Eloquent/Concerns/GuardsAttributes.php @@ -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; diff --git a/Eloquent/Concerns/QueriesRelationships.php b/Eloquent/Concerns/QueriesRelationships.php index 56d116454..1e602ff35 100644 --- a/Eloquent/Concerns/QueriesRelationships.php +++ b/Eloquent/Concerns/QueriesRelationships.php @@ -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); diff --git a/Eloquent/Factories/HasFactory.php b/Eloquent/Factories/HasFactory.php index 2078d9f02..ca37657de 100644 --- a/Eloquent/Factories/HasFactory.php +++ b/Eloquent/Factories/HasFactory.php @@ -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); } /** diff --git a/Eloquent/Relations/Concerns/ComparesRelatedModels.php b/Eloquent/Relations/Concerns/ComparesRelatedModels.php index ca0669887..3dccf1310 100644 --- a/Eloquent/Relations/Concerns/ComparesRelatedModels.php +++ b/Eloquent/Relations/Concerns/ComparesRelatedModels.php @@ -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; diff --git a/Eloquent/Relations/Concerns/InteractsWithPivotTable.php b/Eloquent/Relations/Concerns/InteractsWithPivotTable.php index 034a7d7c8..f09de9451 100644 --- a/Eloquent/Relations/Concerns/InteractsWithPivotTable.php +++ b/Eloquent/Relations/Concerns/InteractsWithPivotTable.php @@ -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)); @@ -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; diff --git a/Eloquent/Relations/MorphPivot.php b/Eloquent/Relations/MorphPivot.php index 6a3f395e7..566e198c9 100644 --- a/Eloquent/Relations/MorphPivot.php +++ b/Eloquent/Relations/MorphPivot.php @@ -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]); } /** @@ -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]); }); } diff --git a/Eloquent/Relations/MorphTo.php b/Eloquent/Relations/MorphTo.php index e743e93ea..cc4298455 100644 --- a/Eloquent/Relations/MorphTo.php +++ b/Eloquent/Relations/MorphTo.php @@ -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); diff --git a/Eloquent/Relations/MorphToMany.php b/Eloquent/Relations/MorphToMany.php index 9cb744537..157202bcc 100644 --- a/Eloquent/Relations/MorphToMany.php +++ b/Eloquent/Relations/MorphToMany.php @@ -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; }); } @@ -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; } diff --git a/Migrations/DatabaseMigrationRepository.php b/Migrations/DatabaseMigrationRepository.php index cf020d64d..c5d525285 100755 --- a/Migrations/DatabaseMigrationRepository.php +++ b/Migrations/DatabaseMigrationRepository.php @@ -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(); } /** @@ -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(); } /** @@ -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(); } /** diff --git a/Query/Builder.php b/Query/Builder.php index f166b28bb..dd762d1dd 100755 --- a/Query/Builder.php +++ b/Query/Builder.php @@ -2820,7 +2820,7 @@ public function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id') } return $this->orderBy($column, 'desc') - ->limit($perPage); + ->limit($perPage); } /** @@ -2840,7 +2840,7 @@ public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id') } return $this->orderBy($column, 'asc') - ->limit($perPage); + ->limit($perPage); } /** @@ -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(); } /** @@ -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(); } /** @@ -3320,7 +3320,7 @@ protected function runPaginationCountQuery($columns = ['*']) protected function cloneForPaginationCount() { return $this->cloneWithout(['orders', 'limit', 'offset']) - ->cloneWithoutBindings(['order']); + ->cloneWithoutBindings(['order']); } /** @@ -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']; @@ -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(); } /**