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 ( dc0110...0351e8 )
by Julien
01:21
created

SyncCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 70%

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 8
c 7
b 2
f 1
lcom 1
cbo 4
dl 0
loc 94
ccs 21
cts 30
cp 0.7
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
C handle() 0 46 7
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 7
    public function __construct(SyncService $sync, WriterInterface $writer)
50
    {
51 7
        parent::__construct();
52 7
        $this->sync = $sync;
53 7
        $this->writer = $writer;
54 7
    }
55
56
    /**
57
     * Execute the console command.
58
     *
59
     * @return mixed
60
     */
61 3
    public function handle()
62
    {
63 3
        list($src, $dest) = $this->getSrcAndDest();
64
65
66 3
        if ($this->option('reverse')) {
67 1
            $switch = $src;
68 1
            $src = $dest;
69 1
            $dest = $switch;
70 1
            unset($switch);
71
        }
72
73 3
        $forceCopy = $this->option('no-interaction');
74 3
        if ($forceCopy) {
75 3
            $this->warn('--no-interaction flag detected - will copy all new keys');
76
        }
77
78
79 3
        $diffs = $this->sync->getDiff($src, $dest);
80
81 3
        foreach ($diffs as $key => $diff) {
82 3
            $action = self::YES;
83 3
            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 3
            if ($action == self::NO) {
93
                continue;
94
            }
95
96 3
            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