diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index adacd735..bd79331d 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -14,8 +14,10 @@ name: rector jobs: rector: uses: yiisoft/actions/.github/workflows/rector.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} with: os: >- ['ubuntu-latest'] php: >- - ['8.0'] + ['8.2'] diff --git a/README.md b/README.md index 001f7857..4d61952c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The preferred way to install this extension is through [composer](http://getcomp Either run ```shell -composer require --prefer-dist yiisoft/db-migration +composer require yiisoft/db-migration ``` or add diff --git a/src/Command/CreateCommand.php b/src/Command/CreateCommand.php index fe87ac38..207dc90a 100644 --- a/src/Command/CreateCommand.php +++ b/src/Command/CreateCommand.php @@ -90,9 +90,9 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $this->migrator->setIO($io); - $this->migrationService->setIO($io); - $this->createService->setIO($io); + $this->migrator->setIo($io); + $this->migrationService->setIo($io); + $this->createService->setIo($io); /** @var string|null $path */ $path = $input->getOption('path'); diff --git a/src/Command/DownCommand.php b/src/Command/DownCommand.php index 1e9e15e7..dcd5f075 100644 --- a/src/Command/DownCommand.php +++ b/src/Command/DownCommand.php @@ -61,9 +61,9 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $this->migrator->setIO($io); - $this->migrationService->setIO($io); - $this->downRunner->setIO($io); + $this->migrator->setIo($io); + $this->migrationService->setIo($io); + $this->downRunner->setIo($io); $this->migrationService->before(self::getDefaultName() ?? ''); @@ -78,9 +78,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::INVALID; } - /** @psalm-var string[] $paths */ + /** @var string[] $paths */ $paths = $input->getOption('path'); - /** @psalm-var string[] $namespaces */ + /** @var string[] $namespaces */ $namespaces = $input->getOption('namespace'); if (!empty($paths) || !empty($namespaces)) { diff --git a/src/Command/HistoryCommand.php b/src/Command/HistoryCommand.php index 2ddc0b8c..34a88a81 100644 --- a/src/Command/HistoryCommand.php +++ b/src/Command/HistoryCommand.php @@ -49,8 +49,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $this->migrator->setIO($io); - $this->migrationService->setIO($io); + $this->migrator->setIo($io); + $this->migrationService->setIo($io); $this->migrationService->before(self::getDefaultName() ?? ''); diff --git a/src/Command/NewCommand.php b/src/Command/NewCommand.php index e2e1a860..40074d27 100644 --- a/src/Command/NewCommand.php +++ b/src/Command/NewCommand.php @@ -56,13 +56,13 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $this->migrator->setIO($io); - $this->migrationService->setIO($io); + $this->migrator->setIo($io); + $this->migrationService->setIo($io); - /** @psalm-var string[] $paths */ + /** @var string[] $paths */ $paths = $input->getOption('path'); - /** @psalm-var string[] $namespaces */ + /** @var string[] $namespaces */ $namespaces = $input->getOption('namespace'); if (!empty($paths) || !empty($namespaces)) { diff --git a/src/Command/RedoCommand.php b/src/Command/RedoCommand.php index 984fc21d..eb2cf042 100644 --- a/src/Command/RedoCommand.php +++ b/src/Command/RedoCommand.php @@ -61,10 +61,10 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $this->migrator->setIO($io); - $this->migrationService->setIO($io); - $this->downRunner->setIO($io); - $this->updateRunner->setIO($io); + $this->migrator->setIo($io); + $this->migrationService->setIo($io); + $this->downRunner->setIo($io); + $this->updateRunner->setIo($io); $this->migrationService->before(self::getDefaultName() ?? ''); @@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::INVALID; } - /** @psalm-var string[] $paths */ + /** @var string[] $paths */ $paths = $input->getOption('path'); - /** @psalm-var string[] $namespaces */ + /** @var string[] $namespaces */ $namespaces = $input->getOption('namespace'); if (!empty($paths) || !empty($namespaces)) { diff --git a/src/Command/UpdateCommand.php b/src/Command/UpdateCommand.php index ffbdbc14..a38a80ec 100644 --- a/src/Command/UpdateCommand.php +++ b/src/Command/UpdateCommand.php @@ -59,14 +59,14 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $this->migrator->setIO($io); - $this->migrationService->setIO($io); - $this->updateRunner->setIO($io); + $this->migrator->setIo($io); + $this->migrationService->setIo($io); + $this->updateRunner->setIo($io); - /** @psalm-var string[] $paths */ + /** @var string[] $paths */ $paths = $input->getOption('path'); - /** @psalm-var string[] $namespaces */ + /** @var string[] $namespaces */ $namespaces = $input->getOption('namespace'); if (!empty($paths) || !empty($namespaces)) { @@ -101,15 +101,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::SUCCESS; } - $n = count($migrations); - $migrationWord = $n === 1 ? 'migration' : 'migrations'; + $migrationsCount = count($migrations); + $migrationWord = $migrationsCount === 1 ? 'migration' : 'migrations'; - if ($limit !== null && $n > $limit) { + if ($limit !== null && $migrationsCount > $limit) { $migrations = array_slice($migrations, 0, $limit); - $output->writeln("Total $limit out of $n new $migrationWord to be applied:\n"); + $output->writeln("Total $limit out of $migrationsCount new $migrationWord to be applied:\n"); } else { - $output->writeln("Total $n new $migrationWord to be applied:\n"); + $output->writeln("Total $migrationsCount new $migrationWord to be applied:\n"); } foreach ($migrations as $i => $migration) { @@ -137,20 +137,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($helper->ask($input, $output, $question)) { $instances = $this->migrationService->makeMigrations($migrations); - $migrationWas = ($n === 1 ? 'migration was' : 'migrations were'); + $migrationWas = ($migrationsCount === 1 ? 'migration was' : 'migrations were'); foreach ($instances as $i => $instance) { try { $this->updateRunner->run($instance, $i + 1); } catch (Throwable $e) { - $output->writeln("\n >>> Total $i out of $n new $migrationWas applied.\n"); + $output->writeln("\n >>> Total $i out of $migrationsCount new $migrationWas applied.\n"); $io->error($i > 0 ? 'Partially updated.' : 'Not updated.'); throw $e; } } - $output->writeln("\n >>> Total $n new $migrationWas applied.\n"); + $output->writeln("\n >>> Total $migrationsCount new $migrationWas applied.\n"); $io->success('Updated successfully.'); } diff --git a/src/Informer/ConsoleMigrationInformer.php b/src/Informer/ConsoleMigrationInformer.php index 3f910b60..523731bb 100644 --- a/src/Informer/ConsoleMigrationInformer.php +++ b/src/Informer/ConsoleMigrationInformer.php @@ -33,7 +33,7 @@ public function endCommand(string $message): void $this->io?->writeln(' ' . $message); } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { $this->io = $io; } diff --git a/src/Informer/MigrationInformerInterface.php b/src/Informer/MigrationInformerInterface.php index aa3ea45a..2b7daf45 100644 --- a/src/Informer/MigrationInformerInterface.php +++ b/src/Informer/MigrationInformerInterface.php @@ -19,5 +19,5 @@ public function beginCommand(string $message): void; public function endCommand(string $message): void; - public function setIO(?SymfonyStyle $io): void; + public function setIo(?SymfonyStyle $io): void; } diff --git a/src/Informer/NullMigrationInformer.php b/src/Informer/NullMigrationInformer.php index 6772d65f..e0c57e9c 100644 --- a/src/Informer/NullMigrationInformer.php +++ b/src/Informer/NullMigrationInformer.php @@ -31,7 +31,7 @@ public function endCommand(string $message): void // do nothing } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { // do nothing } diff --git a/src/MigrationBuilder.php b/src/MigrationBuilder.php index f0f30925..5847ccfb 100644 --- a/src/MigrationBuilder.php +++ b/src/MigrationBuilder.php @@ -197,6 +197,8 @@ public function delete(string $table, array|string $condition = '', array $param * @throws Exception * @throws InvalidConfigException * @throws NotSupportedException + * + * @psalm-param array $columns */ public function createTable(string $table, array $columns, string|null $options = null): void { @@ -204,7 +206,6 @@ public function createTable(string $table, array $columns, string|null $options $this->db->createCommand()->createTable($table, $columns, $options)->execute(); - /** @psalm-var array $columns */ foreach ($columns as $column => $type) { if ($type instanceof ColumnInterface) { $comment = $type->getComment(); @@ -661,7 +662,7 @@ protected function endCommand(float $time): void private function hasIndex(string $table, string $column): bool { - /** @psalm-var Constraint[] $indexes */ + /** @var Constraint[] $indexes */ $indexes = $this->db->getSchema()->getTableIndexes($table); foreach ($indexes as $index) { diff --git a/src/Migrator.php b/src/Migrator.php index 0a6e4925..dfa60afc 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -23,9 +23,9 @@ public function __construct( ) { } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { - $this->informer->setIO($io); + $this->informer->setIo($io); } public function up(MigrationInterface $migration): void @@ -73,7 +73,9 @@ public function getMigrationNameLimit(): ?int return $this->migrationNameLimit = $limit; } - /** @psalm-return array */ + /** + * @psalm-return array + */ public function getHistory(?int $limit = null): array { $this->checkMigrationHistoryTable(); diff --git a/src/Runner/DownRunner.php b/src/Runner/DownRunner.php index 857e58fa..d0dc4b8b 100644 --- a/src/Runner/DownRunner.php +++ b/src/Runner/DownRunner.php @@ -21,7 +21,7 @@ public function __construct(private Migrator $migrator) { } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { $this->io = $io; } @@ -29,7 +29,7 @@ public function setIO(?SymfonyStyle $io): void public function run(RevertibleMigrationInterface $migration, int|null $number = null): void { if ($this->io === null) { - throw new RuntimeException('You need to set output decorator via `setIO()`.'); + throw new RuntimeException('You need to set output decorator via `setIo()`.'); } $num = $number !== null ? $number . '. ' : ''; diff --git a/src/Runner/UpdateRunner.php b/src/Runner/UpdateRunner.php index 61fb5fc8..92b57674 100644 --- a/src/Runner/UpdateRunner.php +++ b/src/Runner/UpdateRunner.php @@ -21,7 +21,7 @@ public function __construct(private Migrator $migrator) { } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { $this->io = $io; } @@ -29,7 +29,7 @@ public function setIO(?SymfonyStyle $io): void public function run(MigrationInterface $migration, int|null $number = null): void { if ($this->io === null) { - throw new RuntimeException('You need to set output decorator via `setIO()`.'); + throw new RuntimeException('You need to set output decorator via `setIo()`.'); } $num = $number !== null ? $number . '. ' : ''; diff --git a/src/Service/Generate/CreateService.php b/src/Service/Generate/CreateService.php index 51c6f7e4..96170af1 100644 --- a/src/Service/Generate/CreateService.php +++ b/src/Service/Generate/CreateService.php @@ -131,7 +131,7 @@ public function setTemplates(array $value = []): void $this->templates = $value; } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { $this->io = $io; } diff --git a/src/Service/MigrationService.php b/src/Service/MigrationService.php index ba3221c3..01eea9a8 100644 --- a/src/Service/MigrationService.php +++ b/src/Service/MigrationService.php @@ -47,9 +47,9 @@ final class MigrationService { private string $createNamespace = ''; private string $createPath = ''; - /** @psalm-var string[] */ + /** @var string[] */ private array $updateNamespaces = []; - /** @psalm-var string[] */ + /** @var string[] */ private array $updatePaths = []; private string $version = '1.0'; private ?SymfonyStyle $io = null; @@ -62,7 +62,7 @@ public function __construct( ) { } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { $this->io = $io; } @@ -227,9 +227,6 @@ public function databaseConnection(): void /** * Creates a new migration instance. * - * @psalm-suppress MoreSpecificReturnType - * @psalm-suppress LessSpecificReturnStatement - * * @param string $class The migration class name. * * @return object The migration instance. @@ -441,10 +438,12 @@ private function getPathFromNamespace(string $path): string { $namespacesPath = []; - /** @psalm-suppress UnresolvableInclude */ + /** + * @psalm-suppress UnresolvableInclude + * @psalm-var array> $map + */ $map = require $this->getVendorDir() . '/composer/autoload_psr4.php'; - /** @psalm-var array> $map */ foreach ($map as $namespace => $directories) { foreach ($directories as $directory) { $namespacesPath[str_replace('\\', '/', trim($namespace, '\\'))] = $directory; @@ -465,10 +464,13 @@ private function getNamespacesFromPath(string $path): array { $namespaces = []; $path = realpath($this->aliases->get($path)) . DIRECTORY_SEPARATOR; - /** @psalm-suppress UnresolvableInclude */ + + /** + * @psalm-suppress UnresolvableInclude + * @psalm-var array> $map + */ $map = require $this->getVendorDir() . '/composer/autoload_psr4.php'; - /** @psalm-var array> $map */ foreach ($map as $namespace => $directories) { foreach ($directories as $directory) { $directory = realpath($directory) . DIRECTORY_SEPARATOR; diff --git a/tests/Common/Runner/AbstractDownRunnerTest.php b/tests/Common/Runner/AbstractDownRunnerTest.php index ed1257aa..6a802afa 100644 --- a/tests/Common/Runner/AbstractDownRunnerTest.php +++ b/tests/Common/Runner/AbstractDownRunnerTest.php @@ -20,7 +20,7 @@ public function testWithoutIO(): void $runner = new DownRunner($this->container->get(Migrator::class)); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('You need to set output decorator via `setIO()`.'); + $this->expectExceptionMessage('You need to set output decorator via `setIo()`.'); $runner->run(new StubRevertibleMigration()); } diff --git a/tests/Common/Runner/AbstractUpRunnerTest.php b/tests/Common/Runner/AbstractUpRunnerTest.php index d92de2aa..199b29f2 100644 --- a/tests/Common/Runner/AbstractUpRunnerTest.php +++ b/tests/Common/Runner/AbstractUpRunnerTest.php @@ -20,7 +20,7 @@ public function testWithoutIO(): void $runner = new UpdateRunner($this->container->get(Migrator::class)); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('You need to set output decorator via `setIO()`.'); + $this->expectExceptionMessage('You need to set output decorator via `setIo()`.'); $runner->run(new StubMigration()); } diff --git a/tests/Common/Service/Database/AbstractListTablesServiceTest.php b/tests/Common/Service/Database/AbstractListTablesServiceTest.php index 723ad781..bfb2029e 100644 --- a/tests/Common/Service/Database/AbstractListTablesServiceTest.php +++ b/tests/Common/Service/Database/AbstractListTablesServiceTest.php @@ -25,7 +25,7 @@ public function testWithoutIO(): void ); $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('You need to set output decorator via `setIO()`.'); + $this->expectExceptionMessage('You need to set output decorator via `setIo()`.'); $service->run(); } diff --git a/tests/Migration/NullMigrationInformerTest.php b/tests/Migration/NullMigrationInformerTest.php index 50e69d4b..d63cd27e 100644 --- a/tests/Migration/NullMigrationInformerTest.php +++ b/tests/Migration/NullMigrationInformerTest.php @@ -15,7 +15,7 @@ public function testSetIO(): void $io = $this->createMock(SymfonyStyle::class); $nullInformer = new NullMigrationInformer(); - $nullInformer->setIO($io); + $nullInformer->setIo($io); $this->expectNotToPerformAssertions(); } diff --git a/tests/Support/Stub/StubMigrationInformer.php b/tests/Support/Stub/StubMigrationInformer.php index 0c0bda8e..36510ce2 100644 --- a/tests/Support/Stub/StubMigrationInformer.php +++ b/tests/Support/Stub/StubMigrationInformer.php @@ -36,7 +36,7 @@ public function getOutput(): string return $this->output; } - public function setIO(?SymfonyStyle $io): void + public function setIo(?SymfonyStyle $io): void { // do nothing }