Completed
Push — master ( ddf2b7...f0be57 )
by Maxime
02:38
created

SyncSwitch::isFromSyncToLive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Distilleries\Contentful\Commands\Sync;
4
5
use Illuminate\Console\Command;
6
7
class SyncSwitch extends Command
8
{
9
    use Traits\SyncTrait;
10
11
    /**
12
     * {@inheritdoc}
13
     */
14
    protected $signature = 'contentful:sync-switch {--preview} {--live}';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $description = 'Dump and switch the database';
20
21
    protected function isFromSyncToLive(): bool
22
    {
23
        $bool = $this->option('live');
24
        return !empty($bool) ? true : false;
25
    }
26
27
    protected function isPreview(): bool
28
    {
29
        $bool = $this->option('preview');
30
        return !empty($bool) ? true : false;
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return void
37
     */
38
    public function handle()
39
    {
40
41
        $isPreview = $this->isPreview();
42
43
        if ($this->isPreview()) {
44
            use_contentful_preview();
45
        }
46
47
        if ($this->isFromSyncToLive()) {
48
            $dumpPath = $this->dumpSync($isPreview, 'mysql_sync');
49
            $this->putSync($dumpPath, $isPreview);
50
        } else {
51
            $this->putSync($this->dumpSync($isPreview), $isPreview, 'mysql_sync');
52
            $this->switchToSyncDb();
53
        }
54
55
    }
56
}
57