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

DatabaseCleanCommand::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 7
Ratio 38.89 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 7
loc 18
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4
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