SaveEnvVariable::argKey()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 112.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Commands\Traits\InteractsWithEnvironment;
6
use Acacha\ForgePublish\Commands\Traits\DiesIfNoEnvFileExists;
7
use Illuminate\Console\Command;
8
9
/**
10
 * Class SaveEnvVariable.
11
 *
12
 * @package Acacha\ForgePublish\Commands
13
 */
14
abstract class SaveEnvVariable extends Command
15
{
16
    use DiesIfNoEnvFileExists, InteractsWithEnvironment;
17
18
    /**
19
     * Env var to set.
20
     *
21
     * @return mixed
22
     */
23
    abstract protected function envVar();
24
25
    /**
26
     * Argument key.
27
     *
28
     * @return mixed
29
     */
30
    abstract protected function argKey();
31
32
    /**
33
     * Question text.
34
     *
35
     * @return mixed
36
     */
37
    abstract protected function questionText();
38
39
    /**
40
     * SaveEnvVariable constructor.
41
     *
42
     */
43
    public function __construct()
44
    {
45
        parent::__construct();
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     */
52
    public function handle()
53
    {
54
        $this->checkIfCommandHaveToBeSkipped();
55
56
        $this->before();
57
58
        $value = $this->argument($this->argKey()) ? $this->argument($this->argKey()) : $this->value() ;
59
        if (!$value) {
60
            $envVar = $this->envVar();
61
            $this->error("Value could not be null for env var: $envVar");
62
            die();
63
        }
64
        $this->addValueToEnv($this->envVar(), $value);
65
66
        $this->info('The Acacha Forge ' . $this->argKey() . ' has been added to file .env with key ' . $this->envVar());
67
68
        $this->after();
69
    }
70
71
    /**
72
     * Before.
73
     */
74
    protected function before()
75
    {
76
        //
77
    }
78
79
    /**
80
     * After.
81
     */
82
    protected function after()
83
    {
84
        //
85
    }
86
87
    /**
88
     * Get value.
89
     *
90
     * @return array|string
91
     */
92
    protected function value()
93
    {
94
        return $this->ask($this->questionText(), $this->default());
95
    }
96
97
    /**
98
     * Check if command have to be skipped.
99
     */
100
    protected function checkIfCommandHaveToBeSkipped()
101
    {
102
        $this->dieIfNoEnvFileIsFound();
103
    }
104
105
    /**
106
     * Default.
107
     */
108
    protected function default()
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
109
    {
110
        return '';
111
    }
112
}
113