GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 430bb8...dc0110 )
by Julien
01:23
created

SyncCommand::handle()   C

Complexity

Conditions 7
Paths 28

Size

Total Lines 46
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 9.7875

Importance

Changes 7
Bugs 2 Features 1
Metric Value
c 7
b 2
f 1
dl 0
loc 46
ccs 16
cts 26
cp 0.6153
rs 6.7272
cc 7
eloc 27
nc 28
nop 0
crap 9.7875
1
<?php
2
/**
3
 * Laravel-Env-Sync
4
 *
5
 * @author Julien Tant - Craftyx <[email protected]>
6
 */
7
8
namespace Jtant\LaravelEnvSync\Console;
9
10
use Illuminate\Console\Command;
11
use Jtant\LaravelEnvSync\SyncService;
12
use Jtant\LaravelEnvSync\Writer\WriterInterface;
13
14
class SyncCommand extends BaseCommand
15
{
16
    const YES = 'y';
17
    const NO = 'n';
18
    const CHANGE = 'c';
19
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'env:sync {--reverse} {--src=} {--dest=}';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Synchronise the .env & .env.example files';
33
34
    /**
35
     * @var SyncService
36
     */
37
    private $sync;
38
39
    /**
40
     * @var WriterInterface
41
     */
42
    private $writer;
43
44
    /**
45
     * Create a new command instance.
46
     *
47
     * @param SyncService $sync
48
     */
49 6
    public function __construct(SyncService $sync, WriterInterface $writer)
50
    {
51 6
        parent::__construct();
52 6
        $this->sync = $sync;
53 6
        $this->writer = $writer;
54 6
    }
55
56
    /**
57
     * Execute the console command.
58
     *
59
     * @return mixed
60
     */
61 2
    public function handle()
62
    {
63 2
        list($src, $dest) = $this->getSrcAndDest();
64
65
66 2
        if ($this->option('reverse')) {
67 1
            $switch = $src;
68 1
            $src = $dest;
69 1
            $dest = $switch;
70 1
            unset($switch);
71
        }
72
73 2
        $forceCopy = $this->option('no-interaction');
74 2
        if ($forceCopy) {
75 2
            $this->warn('--no-interaction flag detected - will copy all new keys');
76
        }
77
78
79 2
        $diffs = $this->sync->getDiff($src, $dest);
80
81 2
        foreach ($diffs as $key => $diff) {
82 2
            $action = self::YES;
83 2
            if (!$forceCopy) {
84
                $question = sprintf("'%s' is not present into your %s file. Its default value is '%s'. Would you like to add it ?", $key, basename($dest), $diff);
85
                $action = $this->choice($question, [
86
                    self::YES => 'Copy the default value',
87
                    self::CHANGE => 'Change the default value',
88
                    self::NO => 'Skip'
89
                ], self::YES);
90
            }
91
92 2
            if ($action == self::NO) {
93
                continue;
94
            }
95
96 2
            if ($action == self::CHANGE) {
97
                $diff = $this->output->ask(sprintf("Please choose a value for '%s' :", $key, $diff), null, function ($value) {
98
                    return $value;
99
                });
100
            }
101
102
            $this->writer->append($dest, $key, $diff);
103
        }
104
105
        $this->info($dest . ' is now synced with ' . $src);
106
    }
107
}
108