MigrateResetCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 6
dl 10
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A run() 0 14 2
A register() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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