Skip to content

Commit

Permalink
[11.x] Enhance doc blocks of the Migrator class (#52033)
Browse files Browse the repository at this point in the history
* Enhance doc blocks of the Migrator.php

* Convert closures to arrow functions
  • Loading branch information
imanghafoori1 authored Jul 5, 2024
1 parent c271b40 commit 867c403
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Console/Migrations/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BaseCommand extends Command
/**
* Get all of the migration paths.
*
* @return array
* @return string[]
*/
protected function getMigrationPaths()
{
Expand Down
79 changes: 38 additions & 41 deletions src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Migrator
/**
* The paths to all of the migration files.
*
* @var array
* @var string[]
*/
protected $paths = [];

Expand Down Expand Up @@ -101,9 +101,9 @@ public function __construct(MigrationRepositoryInterface $repository,
/**
* Run the pending migrations at a given path.
*
* @param array|string $paths
* @param array $options
* @return array
* @param string[]|string $paths
* @param array<string, mixed> $options
* @return string[]
*/
public function run($paths = [], array $options = [])
{
Expand All @@ -127,23 +127,23 @@ public function run($paths = [], array $options = [])
/**
* Get the migration files that have not yet run.
*
* @param array $files
* @param array $ran
* @return array
* @param string[] $files
* @param string[] $ran
* @return string[]
*/
protected function pendingMigrations($files, $ran)
{
return Collection::make($files)
->reject(function ($file) use ($ran) {
return in_array($this->getMigrationName($file), $ran);
})->values()->all();
->reject(fn ($file) => in_array($this->getMigrationName($file), $ran))
->values()
->all();
}

/**
* Run an array of migrations.
*
* @param array $migrations
* @param array $options
* @param string[] $migrations
* @param array<string, mixed> $options
* @return void
*/
public function runPending(array $migrations, array $options = [])
Expand Down Expand Up @@ -220,9 +220,9 @@ protected function runUp($file, $batch, $pretend)
/**
* Rollback the last migration operation.
*
* @param array|string $paths
* @param array $options
* @return array
* @param string[]|string $paths
* @param array<string, mixed> $options
* @return string[]
*/
public function rollback($paths = [], array $options = [])
{
Expand All @@ -247,7 +247,7 @@ public function rollback($paths = [], array $options = [])
/**
* Get the migrations for a rollback operation.
*
* @param array $options
* @param array<string, mixed> $options
* @return array
*/
protected function getMigrationsForRollback(array $options)
Expand All @@ -267,9 +267,9 @@ protected function getMigrationsForRollback(array $options)
* Rollback the given migrations.
*
* @param array $migrations
* @param array|string $paths
* @param array $options
* @return array
* @param string[]|string $paths
* @param array<string, mixed> $options
* @return string[]
*/
protected function rollbackMigrations(array $migrations, $paths, array $options)
{
Expand Down Expand Up @@ -309,7 +309,7 @@ protected function rollbackMigrations(array $migrations, $paths, array $options)
/**
* Rolls all of the currently applied migrations back.
*
* @param array|string $paths
* @param string[]|string $paths
* @param bool $pretend
* @return array
*/
Expand All @@ -334,8 +334,8 @@ public function reset($paths = [], $pretend = false)
/**
* Reset the given migrations.
*
* @param array $migrations
* @param array $paths
* @param string[] $migrations
* @param string[] $paths
* @param bool $pretend
* @return array
*/
Expand All @@ -344,9 +344,7 @@ protected function resetMigrations(array $migrations, array $paths, $pretend = f
// Since the getRan method that retrieves the migration name just gives us the
// migration name, we will format the names into objects with the name as a
// property on the objects so that we can pass it to the rollback method.
$migrations = collect($migrations)->map(function ($m) {
return (object) ['migration' => $m];
})->all();
$migrations = collect($migrations)->map(fn ($m) => (object) ['migration' => $m])->all();

return $this->rollbackMigrations(
$migrations, $paths, compact('pretend')
Expand Down Expand Up @@ -430,9 +428,10 @@ protected function pretendToRun($migration, $method)

$this->write(TwoColumnDetail::class, $name);

$this->write(BulletList::class, collect($this->getQueries($migration, $method))->map(function ($query) {
return $query['query'];
}));
$this->write(
BulletList::class,
collect($this->getQueries($migration, $method))->map(fn ($query) => $query['query'])
);
}

/**
Expand Down Expand Up @@ -532,23 +531,23 @@ protected function getMigrationClass(string $migrationName): string
* Get all of the migration files in a given path.
*
* @param string|array $paths
* @return array
* @return array<string, string>
*/
public function getMigrationFiles($paths)
{
return Collection::make($paths)->flatMap(function ($path) {
return str_ends_with($path, '.php') ? [$path] : $this->files->glob($path.'/*_*.php');
})->filter()->values()->keyBy(function ($file) {
return $this->getMigrationName($file);
})->sortBy(function ($file, $key) {
return $key;
})->all();
return Collection::make($paths)
->flatMap(fn ($path) => str_ends_with($path, '.php') ? [$path] : $this->files->glob($path.'/*_*.php'))
->filter()
->values()
->keyBy(fn ($file) => $this->getMigrationName($file))
->sortBy(fn ($file, $key) => $key)
->all();
}

/**
* Require in all the migration files in a given path.
*
* @param array $files
* @param string[] $files
* @return void
*/
public function requireFiles(array $files)
Expand Down Expand Up @@ -583,7 +582,7 @@ public function path($path)
/**
* Get all of the custom migration paths.
*
* @return array
* @return string[]
*/
public function paths()
{
Expand Down Expand Up @@ -613,9 +612,7 @@ public function usingConnection($name, callable $callback)

$this->setConnection($name);

return tap($callback(), function () use ($previousConnection) {
$this->setConnection($previousConnection);
});
return tap($callback(), fn () => $this->setConnection($previousConnection));
}

/**
Expand Down

0 comments on commit 867c403

Please sign in to comment.