Completed
Push — master ( 7d0f62...257374 )
by Alexander
22s queued 11s
created

UpCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 22
c 2
b 0
f 1
dl 0
loc 36
ccs 0
cts 27
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A execute() 0 26 4
1
<?php
2
namespace Yiisoft\Yii\Cycle\Command;
3
4
use Spiral\Migrations\MigrationInterface;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
class UpCommand extends BaseMigrationCommand
9
{
10
    protected static $defaultName = 'migrate/up';
11
12
    public function configure(): void
13
    {
14
        $this
15
            ->setDescription('Execute all new migrations');
16
    }
17
18
    protected function execute(InputInterface $input, OutputInterface $output)
19
    {
20
        // drop cached schema
21
        $this->cycleOrmHelper->dropCurrentSchemaCache();
22
23
        $this->findMigrations($output);
24
25
        $limit = PHP_INT_MAX;
26
        try {
27
            do {
28
                $migration = $this->migrator->run();
29
                if (!$migration instanceof MigrationInterface) {
30
                    break;
31
                }
32
33
                $state = $migration->getState();
34
                $status = $state->getStatus();
35
                $output->writeln('<fg=cyan>' . $state->getName() . '</>: '
36
                    . (static::$migrationStatus[$status] ?? $status));
37
            } while (--$limit > 0);
38
        } catch (\Throwable $e) {
39
            $output->writeln([
40
                '<fg=red>Error!</>',
41
                $e->getMessage(),
42
            ]);
43
            return;
44
        }
45
    }
46
}
47