DbReCreateCommand::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace MuhmdRaouf\LaravelParatest\Console;
4
5
use Illuminate\Console\Command;
6
use MuhmdRaouf\LaravelParatest\Helper\ConfigHelper;
7
use MuhmdRaouf\LaravelParatest\Database\Schema\Builder;
8
use MuhmdRaouf\LaravelParatest\Database\Schema\GrammarFactory;
9
10 View Code Duplication
class DbReCreateCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'db:recreate
18
        {--dry-run}
19
    ';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Re-creates the database.';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return mixed
42
     */
43
    public function handle(GrammarFactory $grammars)
44
    {
45
        if (app()->environment('testing')) {
46
            $isDryRun = ConfigHelper::isDryRun($this->option('dry-run'));
47
            $configs = ConfigHelper::generateConfig($this->option('database'));
48
49
            $builder = new Builder(
50
                ConfigHelper::makeConnector($configs, $isDryRun, $this->output),
51
                $grammars
52
            );
53
54
            $builder->recreateDatabase($configs);
55
56
57
            $database = $configs['database'];
58
            $this->info("Database $database re-created successfully.");
59
        } else {
60
            $this->warn('You are not in testing environment.');
61
        }
62
    }
63
}
64