SyncSwitch::isFromSyncToLive()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
rs 10
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
    /**
22
     * From sync to live?
23
     *
24
     * @return bool
25
     */
26
    protected function isFromSyncToLive(): bool
27
    {
28
        $bool = $this->option('live');
29
30
        return ! empty($bool) ? true : false;
31
    }
32
33
    /**
34
     * Check if preview?
35
     *
36
     * @return bool
37
     */
38
    protected function isPreview(): bool
39
    {
40
        $bool = $this->option('preview');
41
42
        return ! empty($bool) ? true : false;
43
    }
44
45
    /**
46
     * Execute the console command.
47
     *
48
     * @return void
49
     */
50
    public function handle()
51
    {
52
        $isPreview = $this->isPreview();
53
        if ($this->isPreview()) {
54
            use_contentful_preview();
55
        }
56
57
        if ($this->isFromSyncToLive()) {
58
            $dumpPath = $this->dumpSync($isPreview, 'mysql_sync');
59
            $this->putSync($dumpPath, $isPreview);
60
        } else {
61
            $this->putSync($this->dumpSync($isPreview), $isPreview, 'mysql_sync');
62
            $this->switchToSyncDb();
63
        }
64
    }
65
}
66