Skip to content

Commit

Permalink
Add set prefix to MigrationService setters (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Nov 9, 2023
1 parent 5f8b93d commit b0ce83d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/Command/CreateCommand.php
Expand Up @@ -59,7 +59,7 @@
* ./yii migrate:create post --command=table --path=@root/migrations/blog
* ```
*
* In case {@see createPath} is not set and no namespace is provided, {@see createNamespace} will be used.
* In case {@see $createPath} is not set and no namespace is provided, {@see $createNamespace} will be used.
*/
#[AsCommand('migrate:create', 'Creates a new migration.')]
final class CreateCommand extends Command
Expand Down Expand Up @@ -101,8 +101,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$namespace = $input->getOption('namespace');

if ($path !== null || $namespace !== null) {
$this->migrationService->createPath((string) $path);
$this->migrationService->createNamespace((string) $namespace);
$this->migrationService->setCreatePath((string) $path);
$this->migrationService->setCreateNamespace((string) $namespace);
} else {
$namespace = $this->migrationService->getCreateNamespace();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/NewCommand.php
Expand Up @@ -66,8 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$namespaces = $input->getOption('namespace');

if (!empty($paths) || !empty($namespaces)) {
$this->migrationService->updatePaths($paths);
$this->migrationService->updateNamespaces($namespaces);
$this->migrationService->setUpdatePaths($paths);
$this->migrationService->setUpdateNamespaces($namespaces);
}

$this->migrationService->before(self::getDefaultName() ?? '');
Expand Down
4 changes: 2 additions & 2 deletions src/Command/UpdateCommand.php
Expand Up @@ -70,8 +70,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$namespaces = $input->getOption('namespace');

if (!empty($paths) || !empty($namespaces)) {
$this->migrationService->updatePaths($paths);
$this->migrationService->updateNamespaces($namespaces);
$this->migrationService->setUpdatePaths($paths);
$this->migrationService->setUpdateNamespaces($namespaces);
}

if ($this->migrationService->before(self::getDefaultName() ?? '') === Command::INVALID) {
Expand Down
18 changes: 9 additions & 9 deletions src/Service/MigrationService.php
Expand Up @@ -70,8 +70,8 @@ public function setIO(?SymfonyStyle $io): void
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
*
* It checks the existence of the {@see createPath}, {@see updatePaths}, {@see createNamespace},
* {@see updateNamespaces}.
* It checks the existence of the {@see $createPath}, {@see $updatePaths}, {@see $createNamespace},
* {@see $updateNamespaces}.
*
* @return int Whether the action should continue to be executed.
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ public function getNewMigrations(): array
*
* @psalm-param string[] $value
*/
public function updateNamespaces(array $value): void
public function setUpdateNamespaces(array $value): void
{
$this->updateNamespaces = $value;
}
Expand All @@ -193,12 +193,12 @@ public function updateNamespaces(array $value): void
* This can be either a [path alias](guide:concept-aliases) or a directory path.
*
* Migration classes located at this path should be declared without a namespace.
* Use {@see createNamespace} property in case you are using namespaced migrations.
* Use {@see $createNamespace} property in case you are using namespaced migrations.
*
* If you have set up {@see createNamespace}, you may set this field to `null` in order to disable usage of migrations
* If you have set up {@see $createNamespace}, you may set this field to `null` in order to disable usage of migrations
* that are not namespaced.
*
* In general, to load migrations from different locations, {@see createNamespace} is the preferable solution as the
* In general, to load migrations from different locations, {@see $createNamespace} is the preferable solution as the
* migration name contains the origin of the migration in the history, which is not the case when using multiple
* migration paths.
*
Expand All @@ -207,7 +207,7 @@ public function updateNamespaces(array $value): void
*
* @psalm-param string[] $value
*/
public function updatePaths(array $value): void
public function setUpdatePaths(array $value): void
{
$this->updatePaths = $value;
}
Expand Down Expand Up @@ -318,12 +318,12 @@ public function makeRevertibleMigrations(array $classes): array
);
}

public function createNamespace(string $value): void
public function setCreateNamespace(string $value): void
{
$this->createNamespace = $value;
}

public function createPath(string $value): void
public function setCreatePath(string $value): void
{
$this->createPath = $value;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Common/Command/AbstractCreateCommandTest.php
Expand Up @@ -996,7 +996,7 @@ public function testIncorrectCreatePath(): void
{
MigrationHelper::useMigrationsPath($this->container);

$this->container->get(MigrationService::class)->createPath(__DIR__ . '/not-exists');
$this->container->get(MigrationService::class)->setCreatePath(__DIR__ . '/not-exists');

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);
Expand All @@ -1012,7 +1012,7 @@ public function testWithoutCreatePath(): void
{
MigrationHelper::useMigrationsPath($this->container);

$this->container->get(MigrationService::class)->createPath('');
$this->container->get(MigrationService::class)->setCreatePath('');

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);
Expand All @@ -1032,7 +1032,7 @@ public function testIncorrectCreateNamespace(): void
MigrationHelper::useMigrationsNamespace($this->container);

$this->container->get(MigrationService::class)
->createNamespace('Yiisoft\\Db\\Migration\\TestsRuntime\\NotExists');
->setCreateNamespace('Yiisoft\\Db\\Migration\\TestsRuntime\\NotExists');

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);
Expand All @@ -1048,7 +1048,7 @@ public function testWithoutCreateNamespace(): void
{
MigrationHelper::useMigrationsNamespace($this->container);

$this->container->get(MigrationService::class)->createNamespace('');
$this->container->get(MigrationService::class)->setCreateNamespace('');

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Common/Command/AbstractUpdateCommandTest.php
Expand Up @@ -271,7 +271,7 @@ public function testWithoutUpdatePath(): void
{
MigrationHelper::useMigrationsPath($this->container);

$this->container->get(MigrationService::class)->updatePaths([]);
$this->container->get(MigrationService::class)->setUpdatePaths([]);

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);
Expand All @@ -290,7 +290,7 @@ public function testWithoutUpdateNamespaces(): void
{
MigrationHelper::useMigrationsNamespace($this->container);

$this->container->get(MigrationService::class)->updateNamespaces([]);
$this->container->get(MigrationService::class)->setUpdateNamespaces([]);

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/Service/AbstractMigrationServiceTest.php
Expand Up @@ -46,7 +46,7 @@ public function testGetNewMigrationsWithNotExistNamespace(): void

$service = $this->container->get(MigrationService::class);

$service->updateNamespaces([
$service->setUpdateNamespaces([
MigrationHelper::NAMESPACE,
'Yiisoft\\Db\\Migration\\TestsRuntime\\NotExists',
]);
Expand Down
16 changes: 8 additions & 8 deletions tests/Support/Helper/MigrationHelper.php
Expand Up @@ -26,8 +26,8 @@ public static function useMigrationsPath(ContainerInterface $container): string
{
$service = $container->get(MigrationService::class);

$service->createPath(self::PATH_ALIAS);
$service->updatePaths([self::PATH_ALIAS]);
$service->setCreatePath(self::PATH_ALIAS);
$service->setUpdatePaths([self::PATH_ALIAS]);

self::preparePaths($container);

Expand All @@ -41,8 +41,8 @@ public static function useMigrationsNamespace(ContainerInterface $container): st
{
$service = $container->get(MigrationService::class);

$service->createNamespace(self::NAMESPACE);
$service->updateNamespaces([self::NAMESPACE]);
$service->setCreateNamespace(self::NAMESPACE);
$service->setUpdateNamespaces([self::NAMESPACE]);

self::preparePaths($container);

Expand Down Expand Up @@ -136,9 +136,9 @@ public static function resetPathAndNamespace(ContainerInterface $container): voi
{
$service = $container->get(MigrationService::class);

$service->createPath('');
$service->updatePaths([]);
$service->createNamespace('');
$service->updateNamespaces([]);
$service->setCreatePath('');
$service->setUpdatePaths([]);
$service->setCreateNamespace('');
$service->setUpdateNamespaces([]);
}
}

0 comments on commit b0ce83d

Please sign in to comment.