MigrateResetCommand::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Schnittstabil\Dartisan\Commands;
4
5
use Garden\Cli\Cli;
6
use Garden\Cli\Args;
7
use Illuminate\Database\Migrations\Migrator;
8
use Schnittstabil\Dartisan\OutputInterface;
9
10
class MigrateResetCommand extends Command
11
{
12
    use DatabaseAwareCommandTrait;
13
    use MigrationAwareCommandTrait;
14
15
    public static $name = 'migrate:reset';
16
17
    /**
18
     * @var Migrator
19
     */
20
    protected $migrator;
21
22
    /**
23
     * @var string
24
     */
25
    protected $migrationsPath;
26
27
    public function __construct(
28
        Args $args,
29
        OutputInterface $output,
30
        Migrator $migrator,
31
        string $migrationsPath
32
    ) {
33
        parent::__construct($args, $output);
34
        $this->migrator = $migrator;
35
        $this->migrationsPath = $migrationsPath;
36
    }
37
38
    public function run()
39
    {
40
        if (!$this->migrator->repositoryExists()) {
41
            $this->output->error('No migration table found.');
0 ignored issues
show
Bug introduced by
The method error cannot be called on $this->output (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
42
43
            return 1;
44
        }
45
46
        $path = $this->args->getOpt('path', $this->migrationsPath);
47
        $pretend = $this->args->getOpt('pretend', false);
48
        $this->migrator->reset([$path], $pretend);
49
50
        return 0;
51
    }
52
53 View Code Duplication
    public static function register(Cli $cli)
54
    {
55
        $cli = static::registerDatabaseOpts($cli);
56
        $cli = static::registerMigrationOpts($cli);
57
58
        return $cli
59
            ->command(static::$name)
60
            ->description('Rollback all database migrations.')
61
            ->opt('pretend', 'Dump the SQL queries that would be run.');
62
    }
63
}
64