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

SyncSwitch   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

3 Methods

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