ListTargets::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\MigrationTargetMap;
12
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...
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
final class ListTargets extends Command
18
{
19
    private MigrationTargetMap $migrationTargetMap;
20
21
    public function __construct(MigrationTargetMap $migrationTargetMap)
22
    {
23
        $this->migrationTargetMap = $migrationTargetMap;
24
25
        parent::__construct();
26
    }
27
28
    protected function configure(): void
29
    {
30
        $this
31
            ->setName('migrate:ls')
32
            ->setDescription('Lists available migration targets.')
33
            ->addOption(
34
                'target',
35
                null,
36
                InputOption::VALUE_REQUIRED,
37
                'Name of the target to list.'
38
            );
39
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output): int
42
    {
43
        $target = $input->getOption('target');
44
        foreach ($this->migrationTargetMap as $targetKey => $migrationTarget) {
45
            if ($target && $target !== $targetKey) {
46
                continue;
47
            }
48
            $migrationList = $migrationTarget->getMigrationList();
49
            $executedMigrations = $migrationList->getExecutedMigrations();
50
            $pendingMigrations = $migrationList->getPendingMigrations();
51
            $output->writeln('Summary for migration target <options=bold>'.$targetKey.'</>');
52
            $output->writeln('  Enabled: '.($migrationTarget->isEnabled() ? 'true' : 'false'));
53
            $output->writeln('  Executed Migrations: '.count($executedMigrations));
54
            $output->writeln('  Pending Migrations: '.count($pendingMigrations));
55
        }
56
57
        return 0;
58
    }
59
}
60