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

DownCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 23
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A execute() 0 22 3
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 DownCommand extends BaseMigrationCommand
9
{
10
    protected static $defaultName = 'migrate/down';
11
12
    public function configure(): void
13
    {
14
        $this
15
            ->setDescription('Rollback last migration');
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
        try {
26
            $migration = $this->migrator->rollback();
27
            if (!$migration instanceof MigrationInterface) {
28
                throw new \Exception('Migration not found');
29
            }
30
31
            $state = $migration->getState();
32
            $status = $state->getStatus();
33
            $output->writeln('<fg=cyan>' . $state->getName() . '</>: ' . (static::$migrationStatus[$status] ?? $status));
34
        } catch (\Throwable $e) {
35
            $output->writeln([
36
                '<fg=red>Error!</>',
37
                $e->getMessage(),
38
            ]);
39
            return;
40
        }
41
    }
42
}
43