MigrateUp   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 55
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 16 1
A execute() 0 25 6
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Boot\Console\Command\Migrate;
10
11
use Daikon\Dbal\Migration\MigrationInterface;
12
use Daikon\Dbal\Migration\MigrationTargetMap;
13
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
final class MigrateUp extends Command
19
{
20
    private MigrationTargetMap $migrationTargetMap;
21
22
    public function __construct(MigrationTargetMap $migrationTargetMap)
23
    {
24
        $this->migrationTargetMap = $migrationTargetMap;
25
26
        parent::__construct();
27
    }
28
29
    protected function configure(): void
30
    {
31
        $this
32
            ->setName('migrate:up')
33
            ->setDescription('Migrate up to a specified migration version.')
34
            ->addOption(
35
                'target',
36
                null,
37
                InputOption::VALUE_REQUIRED,
38
                'Name of the target to migrate (if omitted all enabled targets will be migrated).'
39
            )
40
            ->addOption(
41
                'to',
42
                null,
43
                InputOption::VALUE_REQUIRED,
44
                'The version to migrate towards (if omitted all pendings migrations will be executed).'
45
            );
46
    }
47
48
    protected function execute(InputInterface $input, OutputInterface $output): int
49
    {
50
        $target = $input->getOption('target');
51
        $version = intval($input->getOption('to'));
52
53
        foreach ($this->migrationTargetMap->getEnabledTargets() as $targetKey => $migrationTarget) {
54
            if ($target && $target !== $targetKey) {
55
                continue;
56
            }
57
            $output->writeln(sprintf('Executing migrations for target <options=bold>%s</>', $targetKey));
58
            $executedMigrations = $migrationTarget->migrate(MigrationInterface::MIGRATE_UP, $version);
59
            if ($executedMigrations->count() > 0) {
60
                foreach ($executedMigrations as $migration) {
61
                    $output->writeln(sprintf(
62
                        '  <info>Executed migration version %d (%s)</info>',
63
                        $migration->getVersion(),
64
                        $migration->getName()
65
                    ));
66
                }
67
            } else {
68
                $output->writeln('  <comment>No pending migrations found</comment>');
69
            }
70
        }
71
72
        return 0;
73
    }
74
}
75