SyncSwitch   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 56
ccs 0
cts 22
cp 0
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isFromSyncToLive() 0 5 2
A handle() 0 13 3
A isPreview() 0 5 2
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