DatabaseCleanCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 14.89 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 7
loc 47
ccs 0
cts 10
cp 0
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
    public function handle(Migrator $migrator)
38
    {
39
        if (!$this->confirmToProceed()) {
40
            return;
41
        }
42
43
        $migrator->makeLogTable();
44
45
        $installed_migrations = $migrator->installedMigrationsByDesc();
46
47 View Code Duplication
        foreach ($installed_migrations as $group => $migrations) {
48
            foreach ($migrations as $data) {
49
                $this->infoDowngrade($group, $data->version, $data->class);
50
51
                $migrator->doDowngrade($group, $data->version);
52
            }
53
        }
54
    }
55
}
56