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 ( e2937c...75a65c )
by Julien
03:48
created

SyncCommand::handle()   C

Complexity

Conditions 7
Paths 28

Size

Total Lines 44
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 8.1426

Importance

Changes 7
Bugs 2 Features 1
Metric Value
c 7
b 2
f 1
dl 0
loc 44
ccs 20
cts 28
cp 0.7143
rs 6.7272
cc 7
eloc 27
nc 28
nop 0
crap 8.1426
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 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
    /**
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
        $first = base_path('.env.example');
64 2
        $second = base_path('.env');
65
66 2
        if ($this->option('reverse')) {
67 1
            $switch = $first;
68 1
            $first = $second;
69 1
            $second = $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($first, $second);
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 ? [y=yes/n=no/c=change default value]", $key, basename($second), $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->ask(sprintf("Please choose a value for '%s' :", $key, $diff));
98
            }
99
100 2
            $this->writer->append($second, $key, $diff);
101
        }
102
103 2
        $this->info($second . ' is now synced with ' . $first);
104 2
    }
105
}
106