Completed
Push — master ( aed5e6...e7b04e )
by Fumio
01:47
created

DatabaseCleanCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 14.89 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 7
loc 47
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 7 18 4

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 Jumilla\Versionia\Laravel\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
use Jumilla\Versionia\Laravel\Migrator;
8
9
class DatabaseCleanCommand extends Command
10
{
11
    use DatabaseCommandTrait;
12
    use ConfirmableTrait;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'database:clean
20
        {--force : Force the operation to run when in production.}
21
    ';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Database migrate to clean';
29
30
    /**
31
     * Execute the console command.
32
     *
33
     * @param \Jumilla\Versionia\Laravel\Migrator $migrator
34
     *
35
     * @return mixed
36
     */
37 4
    public function handle(Migrator $migrator)
38
    {
39 4
        if (!$this->confirmToProceed()) {
40 1
            return;
41
        }
42
43 3
        $migrator->makeLogTable();
44
45 3
        $installed_migrations = $migrator->installedMigrationsByDesc();
46
47 3 View Code Duplication
        foreach ($installed_migrations as $group => $migrations) {
48 1
            foreach ($migrations as $data) {
49 1
                $this->infoDowngrade($group, $data->version, $data->class);
50
51 1
                $migrator->doDowngrade($group, $data->version);
52
            }
53
        }
54 3
    }
55
}
56