MigrateInstallCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 21.95 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 9
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A run() 0 13 2
A register() 9 9 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\MigrationRepositoryInterface;
8
use Schnittstabil\Dartisan\OutputInterface;
9
10
class MigrateInstallCommand extends Command
11
{
12
    use DatabaseAwareCommandTrait;
13
    use MigrationAwareCommandTrait;
14
15
    public static $name = 'migrate:install';
16
    protected $repository;
17
18
    public function __construct(
19
        Args $args,
20
        OutputInterface $output,
21
        MigrationRepositoryInterface $repository
22
    ) {
23
        parent::__construct($args, $output);
24
        $this->repository = $repository;
25
    }
26
27
    public function run()
28
    {
29
        if ($this->repository->repositoryExists()) {
30
            $this->output->info('Migration table already exists.');
0 ignored issues
show
Bug introduced by
The method info 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...
31
32
            return 0;
33
        }
34
35
        $this->repository->createRepository();
36
        $this->output->info('Migration table created successfully.');
0 ignored issues
show
Bug introduced by
The method info 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...
37
38
        return 0;
39
    }
40
41 View Code Duplication
    public static function register(Cli $cli)
42
    {
43
        $cli = static::registerDatabaseOpts($cli);
44
        $cli = static::registerMigrationOpts($cli);
45
46
        return $cli
47
            ->command(static::$name)
48
            ->description('Create the migration repository.');
49
    }
50
}
51