EnvDelCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace msztorc\LaravelEnv\Commands;
4
5
use Illuminate\Console\Command;
6
use msztorc\LaravelEnv\Commands\Traits\CommandValidator;
7
use msztorc\LaravelEnv\Env;
8
9
class EnvDelCommand extends Command
10
{
11
    use CommandValidator;
12
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'env:del {key}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Delete variable from an environment file';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    public function handle()
43
    {
44
        $key = $this->argument('key');
45
46
        if (!is_null($key)) {
47
            $this->isValidKey((string)$key);
48
        }
49
50
        $env = new Env();
51
        if (!$env->exists((string)$key)) {
52
            $this->info("There is no variable {$key}");
53
        } else {
54
            $env->deleteVariable((string)$key);
55
            $this->info("Variable '{$key}' has been deleted");
56
        }
57
    }
58
}
59