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 ( 750c85...2497af )
by Julien
03:55
created

SyncCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 2
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 Jtant\LaravelEnvSync\SyncService;
11
use Illuminate\Console\Command;
12
use Jtant\LaravelEnvSync\Writer\WriterInterface;
13
14
class SyncCommand extends Command
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}';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Synchronise the .env & .env.example files';
33
    /**
34
     * @var SyncService
35
     */
36
    private $sync;
37
    /**
38
     * @var WriterInterface
39
     */
40
    private $writer;
41
42
    /**
43
     * Create a new command instance.
44
     *
45
     * @param SyncService $sync
46
     */
47
    public function __construct(SyncService $sync, WriterInterface $writer)
48
    {
49
        parent::__construct();
50
        $this->sync = $sync;
51
        $this->writer = $writer;
52
    }
53
54
    /**
55
     * Execute the console command.
56
     *
57
     * @return mixed
58
     */
59
    public function handle()
60
    {
61
        $first = base_path('.env.example');
62
        $second = base_path('.env');
63
64
        if ($this->option('reverse')) {
65
            $switch = $first;
66
            $first = $second;
67
            $second = $switch;
68
            unset($switch);
69
        }
70
71
        $diffs = $this->sync->getDiff($first, $second);
72
73
        foreach ($diffs as $key => $diff) {
74
            $question = sprintf("'%s' is not present into your %s file. It's default value is '%s'. Would you like to add it ? [y=yes/n=no/c=change default value]", $key, basename($second), $diff);
75
            $action = strtolower(trim($this->ask($question, self::YES)));
76
            if ($action == self::NO) {
77
                continue;
78
            }
79
80
            if ($action == self::CHANGE) {
81
                $diff = $this->ask(sprintf("Please choose a value for '%s' :", $key, $diff));
82
            }
83
84
            $this->writer->append($second, $key, $diff);
85
        }
86
87
        $this->info($second . ' is now synced with ' . $first);
88
    }
89
}
90