Skip to content

Commit e9caffe

Browse files
committed
Polish migration file accessors
1 parent c9b19bc commit e9caffe

7 files changed

Lines changed: 33 additions & 33 deletions

File tree

src/Console/FreshCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ class FreshCommand extends Command
3131
*/
3232
public function handle(
3333
Migrator $migrator,
34-
MigrationRepository $migrationRepository,
35-
IndexManagerInterface $indexManager
34+
IndexManagerInterface $index,
35+
MigrationRepository $migrations,
3636
): int {
3737
$migrator->setOutput($this->output);
3838

3939
if (! $this->confirmToProceed() || ! $migrator->isReady()) {
4040
return 1;
4141
}
4242

43-
$indexManager->drop('*');
43+
$index->drop('*');
4444

45-
$migrationRepository->deleteAll();
45+
$migrations->deleteAll();
4646

4747
$migrator->migrateAll();
4848

src/Console/MakeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MakeCommand extends Command
2727
/**
2828
* Execute the console command.
2929
*/
30-
public function handle(Filesystem $filesystem, MigrationStorage $migrationStorage): int
30+
public function handle(Filesystem $filesystem, MigrationStorage $migrations): int
3131
{
3232
$name = Str::snake(trim($this->argument('name')));
3333

@@ -37,7 +37,7 @@ public function handle(Filesystem $filesystem, MigrationStorage $migrationStorag
3737
$stub = $filesystem->get(__DIR__.'/stubs/migration.blank.stub');
3838
$content = str_replace('DummyClass', $className, $stub);
3939

40-
$migrationStorage->create($fileName, $content);
40+
$migrations->create($fileName, $content);
4141

4242
$this->output->writeln('<info>Created migration:</info> '.$fileName);
4343

src/Factories/MigrationFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class MigrationFactory
1616
*/
1717
public function makeFromFile(MigrationFile $file): MigrationInterface
1818
{
19-
require_once $file->getPath();
19+
require_once $file->path();
2020

21-
$className = Str::studly(implode('_', array_slice(explode('_', $file->getName()), 4)));
21+
$className = Str::studly(implode('_', array_slice(explode('_', $file->name()), 4)));
2222

2323
return resolve($className);
2424
}

src/Filesystem/MigrationFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public function __construct(
1717
/**
1818
* Get the migration file name without its extension.
1919
*/
20-
public function getName(): string
20+
public function name(): string
2121
{
2222
return basename($this->filePath, '.php');
2323
}
2424

2525
/**
2626
* Get the full migration file path.
2727
*/
28-
public function getPath(): string
28+
public function path(): string
2929
{
3030
return $this->filePath;
3131
}

src/Migrator.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function migrateAll(): self
6363
$migratedFileNames = $this->migrationRepository->getAll();
6464

6565
$nonMigratedFiles = $files->filter(function (MigrationFile $file) use ($migratedFileNames) {
66-
return ! $migratedFileNames->contains($file->getName());
66+
return ! $migratedFileNames->contains($file->name());
6767
});
6868

6969
$this->migrate($nonMigratedFiles);
@@ -80,10 +80,10 @@ public function rollbackOne(string $fileName): self
8080

8181
if (is_null($file)) {
8282
$this->output->writeln('<error>Migration is not found:</error> '.$fileName);
83-
} elseif (! $this->migrationRepository->exists($file->getName())) {
84-
$this->output->writeln('<error>Migration is not yet migrated:</error> '.$file->getName());
83+
} elseif (! $this->migrationRepository->exists($file->name())) {
84+
$this->output->writeln('<error>Migration is not yet migrated:</error> '.$file->name());
8585
} else {
86-
$this->rollback(collect([$file->getName()]));
86+
$this->rollback(collect([$file->name()]));
8787
}
8888

8989
return $this;
@@ -127,9 +127,9 @@ public function showStatus(): self
127127

128128
$rows = $files->map(function (MigrationFile $file) use ($migratedFileNames, $migratedLastBatchFileNames) {
129129
return [
130-
$migratedFileNames->contains($file->getName()) ? '<info>Yes</info>' : '<comment>No</comment>',
131-
$migratedLastBatchFileNames->contains($file->getName()) ? '<info>Yes</info>' : '<comment>No</comment>',
132-
$file->getName(),
130+
$migratedFileNames->contains($file->name()) ? '<info>Yes</info>' : '<comment>No</comment>',
131+
$migratedLastBatchFileNames->contains($file->name()) ? '<info>Yes</info>' : '<comment>No</comment>',
132+
$file->name(),
133133
];
134134
})->toArray();
135135

@@ -154,14 +154,14 @@ protected function migrate(Collection $files): self
154154
$nextBatchNumber = $this->migrationRepository->getLastBatchNumber() + 1;
155155

156156
$files->each(function (MigrationFile $file) use ($nextBatchNumber) {
157-
$this->output->writeln('<comment>Migrating:</comment> '.$file->getName());
157+
$this->output->writeln('<comment>Migrating:</comment> '.$file->name());
158158

159159
$migration = $this->migrationFactory->makeFromFile($file);
160160
$migration->up();
161161

162-
$this->migrationRepository->insert($file->getName(), $nextBatchNumber);
162+
$this->migrationRepository->insert($file->name(), $nextBatchNumber);
163163

164-
$this->output->writeln('<info>Migrated:</info> '.$file->getName());
164+
$this->output->writeln('<info>Migrated:</info> '.$file->name());
165165
});
166166

167167
return $this;
@@ -186,22 +186,22 @@ protected function rollback(Collection $fileNames): self
186186
$this->output->writeln(
187187
'<error>Migration is not found:</error> '.
188188
implode(',', $fileNames->diff($files->map(function (MigrationFile $file) {
189-
return $file->getName();
189+
return $file->name();
190190
}))->toArray())
191191
);
192192

193193
return $this;
194194
}
195195

196196
$files->each(function (MigrationFile $file) {
197-
$this->output->writeln('<comment>Rolling back:</comment> '.$file->getName());
197+
$this->output->writeln('<comment>Rolling back:</comment> '.$file->name());
198198

199199
$migration = $this->migrationFactory->makeFromFile($file);
200200
$migration->down();
201201

202-
$this->migrationRepository->delete($file->getName());
202+
$this->migrationRepository->delete($file->name());
203203

204-
$this->output->writeln('<info>Rolled back:</info> '.$file->getName());
204+
$this->output->writeln('<info>Rolled back:</info> '.$file->name());
205205
});
206206

207207
return $this;

tests/Integration/Filesystem/MigrationStorageTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function test_file_can_be_created(): void
3232

3333
$file = $this->migrationStorage->create($fileName, 'content');
3434

35-
$this->assertSame($fileName, $file->getName());
36-
$this->assertFileExists($file->getPath());
37-
$this->assertStringEqualsFile($file->getPath(), 'content');
35+
$this->assertSame($fileName, $file->name());
36+
$this->assertFileExists($file->path());
37+
$this->assertStringEqualsFile($file->path(), 'content');
3838

39-
@unlink($file->getPath());
39+
@unlink($file->path());
4040
}
4141

4242
public function test_directory_is_created_along_with_file(): void
@@ -53,7 +53,7 @@ public function test_directory_is_created_along_with_file(): void
5353

5454
$this->assertDirectoryExists($secondLevelDirectory);
5555

56-
@unlink($file->getPath());
56+
@unlink($file->path());
5757
@rmdir($secondLevelDirectory);
5858
@rmdir($firstLevelDirectory);
5959
}
@@ -74,7 +74,7 @@ public function test_file_can_be_found_if_exists(string $fileName): void
7474
/** @var MigrationFile $file */
7575
$file = $this->migrationStorage->findByName($fileName);
7676

77-
$this->assertSame(basename(trim($fileName), '.php'), $file->getName());
77+
$this->assertSame(basename(trim($fileName), '.php'), $file->name());
7878
}
7979

8080
public static function nonExistingFileNameProvider(): array
@@ -105,7 +105,7 @@ public function test_all_files_within_migrations_directory_can_be_retrieved(): v
105105
'2019_08_10_142230_update_test_index_mapping',
106106
],
107107
$files->map(function (MigrationFile $file) {
108-
return $file->getName();
108+
return $file->name();
109109
})->toArray()
110110
);
111111
}

tests/Unit/Filesystem/MigrationFileTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public function test_path_getter(): void
1313
{
1414
$this->assertSame(
1515
static::FULL_PATH,
16-
(new MigrationFile(static::FULL_PATH))->getPath()
16+
(new MigrationFile(static::FULL_PATH))->path()
1717
);
1818
}
1919

2020
public function test_name_getter(): void
2121
{
2222
$this->assertSame(
2323
basename(static::FULL_PATH, '.php'),
24-
(new MigrationFile(static::FULL_PATH))->getName()
24+
(new MigrationFile(static::FULL_PATH))->name()
2525
);
2626
}
2727
}

0 commit comments

Comments
 (0)