Skip to content

Commit 867c403

Browse files
[11.x] Enhance doc blocks of the Migrator class (#52033)
* Enhance doc blocks of the Migrator.php * Convert closures to arrow functions
1 parent c271b40 commit 867c403

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

src/Illuminate/Database/Console/Migrations/BaseCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class BaseCommand extends Command
99
/**
1010
* Get all of the migration paths.
1111
*
12-
* @return array
12+
* @return string[]
1313
*/
1414
protected function getMigrationPaths()
1515
{

src/Illuminate/Database/Migrations/Migrator.php

+38-41
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Migrator
6060
/**
6161
* The paths to all of the migration files.
6262
*
63-
* @var array
63+
* @var string[]
6464
*/
6565
protected $paths = [];
6666

@@ -101,9 +101,9 @@ public function __construct(MigrationRepositoryInterface $repository,
101101
/**
102102
* Run the pending migrations at a given path.
103103
*
104-
* @param array|string $paths
105-
* @param array $options
106-
* @return array
104+
* @param string[]|string $paths
105+
* @param array<string, mixed> $options
106+
* @return string[]
107107
*/
108108
public function run($paths = [], array $options = [])
109109
{
@@ -127,23 +127,23 @@ public function run($paths = [], array $options = [])
127127
/**
128128
* Get the migration files that have not yet run.
129129
*
130-
* @param array $files
131-
* @param array $ran
132-
* @return array
130+
* @param string[] $files
131+
* @param string[] $ran
132+
* @return string[]
133133
*/
134134
protected function pendingMigrations($files, $ran)
135135
{
136136
return Collection::make($files)
137-
->reject(function ($file) use ($ran) {
138-
return in_array($this->getMigrationName($file), $ran);
139-
})->values()->all();
137+
->reject(fn ($file) => in_array($this->getMigrationName($file), $ran))
138+
->values()
139+
->all();
140140
}
141141

142142
/**
143143
* Run an array of migrations.
144144
*
145-
* @param array $migrations
146-
* @param array $options
145+
* @param string[] $migrations
146+
* @param array<string, mixed> $options
147147
* @return void
148148
*/
149149
public function runPending(array $migrations, array $options = [])
@@ -220,9 +220,9 @@ protected function runUp($file, $batch, $pretend)
220220
/**
221221
* Rollback the last migration operation.
222222
*
223-
* @param array|string $paths
224-
* @param array $options
225-
* @return array
223+
* @param string[]|string $paths
224+
* @param array<string, mixed> $options
225+
* @return string[]
226226
*/
227227
public function rollback($paths = [], array $options = [])
228228
{
@@ -247,7 +247,7 @@ public function rollback($paths = [], array $options = [])
247247
/**
248248
* Get the migrations for a rollback operation.
249249
*
250-
* @param array $options
250+
* @param array<string, mixed> $options
251251
* @return array
252252
*/
253253
protected function getMigrationsForRollback(array $options)
@@ -267,9 +267,9 @@ protected function getMigrationsForRollback(array $options)
267267
* Rollback the given migrations.
268268
*
269269
* @param array $migrations
270-
* @param array|string $paths
271-
* @param array $options
272-
* @return array
270+
* @param string[]|string $paths
271+
* @param array<string, mixed> $options
272+
* @return string[]
273273
*/
274274
protected function rollbackMigrations(array $migrations, $paths, array $options)
275275
{
@@ -309,7 +309,7 @@ protected function rollbackMigrations(array $migrations, $paths, array $options)
309309
/**
310310
* Rolls all of the currently applied migrations back.
311311
*
312-
* @param array|string $paths
312+
* @param string[]|string $paths
313313
* @param bool $pretend
314314
* @return array
315315
*/
@@ -334,8 +334,8 @@ public function reset($paths = [], $pretend = false)
334334
/**
335335
* Reset the given migrations.
336336
*
337-
* @param array $migrations
338-
* @param array $paths
337+
* @param string[] $migrations
338+
* @param string[] $paths
339339
* @param bool $pretend
340340
* @return array
341341
*/
@@ -344,9 +344,7 @@ protected function resetMigrations(array $migrations, array $paths, $pretend = f
344344
// Since the getRan method that retrieves the migration name just gives us the
345345
// migration name, we will format the names into objects with the name as a
346346
// property on the objects so that we can pass it to the rollback method.
347-
$migrations = collect($migrations)->map(function ($m) {
348-
return (object) ['migration' => $m];
349-
})->all();
347+
$migrations = collect($migrations)->map(fn ($m) => (object) ['migration' => $m])->all();
350348

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

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

433-
$this->write(BulletList::class, collect($this->getQueries($migration, $method))->map(function ($query) {
434-
return $query['query'];
435-
}));
431+
$this->write(
432+
BulletList::class,
433+
collect($this->getQueries($migration, $method))->map(fn ($query) => $query['query'])
434+
);
436435
}
437436

438437
/**
@@ -532,23 +531,23 @@ protected function getMigrationClass(string $migrationName): string
532531
* Get all of the migration files in a given path.
533532
*
534533
* @param string|array $paths
535-
* @return array
534+
* @return array<string, string>
536535
*/
537536
public function getMigrationFiles($paths)
538537
{
539-
return Collection::make($paths)->flatMap(function ($path) {
540-
return str_ends_with($path, '.php') ? [$path] : $this->files->glob($path.'/*_*.php');
541-
})->filter()->values()->keyBy(function ($file) {
542-
return $this->getMigrationName($file);
543-
})->sortBy(function ($file, $key) {
544-
return $key;
545-
})->all();
538+
return Collection::make($paths)
539+
->flatMap(fn ($path) => str_ends_with($path, '.php') ? [$path] : $this->files->glob($path.'/*_*.php'))
540+
->filter()
541+
->values()
542+
->keyBy(fn ($file) => $this->getMigrationName($file))
543+
->sortBy(fn ($file, $key) => $key)
544+
->all();
546545
}
547546

548547
/**
549548
* Require in all the migration files in a given path.
550549
*
551-
* @param array $files
550+
* @param string[] $files
552551
* @return void
553552
*/
554553
public function requireFiles(array $files)
@@ -583,7 +582,7 @@ public function path($path)
583582
/**
584583
* Get all of the custom migration paths.
585584
*
586-
* @return array
585+
* @return string[]
587586
*/
588587
public function paths()
589588
{
@@ -613,9 +612,7 @@ public function usingConnection($name, callable $callback)
613612

614613
$this->setConnection($name);
615614

616-
return tap($callback(), function () use ($previousConnection) {
617-
$this->setConnection($previousConnection);
618-
});
615+
return tap($callback(), fn () => $this->setConnection($previousConnection));
619616
}
620617

621618
/**

0 commit comments

Comments
 (0)