Passed
Push — master ( 77392d...e0a3bd )
by Kirill
08:16 queued 11s
created

MigrateCommand::perform()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 13
c 0
b 0
f 0
nc 9
nop 0
dl 0
loc 23
rs 9.2222
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Command\Migrate;
13
14
use Symfony\Component\Console\Input\InputOption;
15
16
final class MigrateCommand extends AbstractCommand
17
{
18
    protected const NAME        = 'migrate';
19
    protected const DESCRIPTION = 'Perform one or all outstanding migrations';
20
    protected const OPTIONS     = [
21
        ['one', 'o', InputOption::VALUE_NONE, 'Execute only one (first) migration'],
22
    ];
23
24
    /**
25
     * Execute one or multiple migrations.
26
     */
27
    public function perform(): void
28
    {
29
        if (!$this->verifyEnvironment()) {
30
            return;
31
        }
32
33
        $this->migrator->configure();
34
35
        $found = false;
36
        $count = $this->option('one') ? 1 : PHP_INT_MAX;
37
38
        while ($count > 0 && ($migration = $this->migrator->run())) {
39
            $found = true;
40
            $count--;
41
42
            $this->sprintf(
43
                "<info>Migration <comment>%s</comment> was successfully executed.</info>\n",
44
                $migration->getState()->getName()
45
            );
46
        }
47
48
        if (!$found) {
49
            $this->writeln('<fg=red>No outstanding migrations were found.</fg=red>');
50
        }
51
    }
52
}
53