PublishEnvProduction::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Commands\Traits\ChecksEnv;
6
use Acacha\ForgePublish\Commands\Traits\ChecksSSHConnection;
7
use Acacha\ForgePublish\Commands\Traits\RunsSSHCommands;
8
use GuzzleHttp\Client;
9
use Illuminate\Console\Command;
10
use Illuminate\Support\Facades\File;
11
12
/**
13
 * Class PublishEnvProduction.
14
 *
15
 * @package Acacha\ForgePublish\Commands
16
 */
17
class PublishEnvProduction extends Command
18
{
19
    use ChecksEnv, RunsSSHCommands;
20
21
    /**
22
     * Server name
23
     *
24
     * @var String
25
     */
26
    protected $server;
27
28
    /**
29
     * Domain
30
     *
31
     * @var String
32
     */
33
    protected $domain;
34
35
    /**
36
     * Local path.
37
     *
38
     * @var String
39
     */
40
    protected $localPath;
41
42
    /**
43
     * Remote path.
44
     *
45
     * @var String
46
     */
47
    protected $remotePath;
48
49
    /**
50
     * The name and signature of the console command.
51
     *
52
     * @var string
53
     */
54
    protected $signature = 'publish:env-production {--server=} {--domain=}';
55
56
    /**
57
     * The console command description.
58
     *
59
     * @var string
60
     */
61
    protected $description = 'Install local .env.production to .env in production';
62
63
    /**
64
     * Guzzle http client.
65
     *
66
     * @var Client
67
     */
68
    protected $http;
69
70
    /**
71
     * Create a new command instance.
72
     *
73
     */
74
    public function __construct(Client $http)
75
    {
76
        parent::__construct();
77
        $this->http = $http;
78
    }
79
80
    /**
81
     * Execute the console command.
82
     *
83
     */
84
    public function handle()
85
    {
86
        $this->abortCommandExecution();
87
        $this->remotePath = $this->domain . '/.env';
88
        $this->runScp($this->localPath, $this->remotePath, null, true);
89
    }
90
91
    /**
92
     * Abort command execution?
93
     */
94
    protected function abortCommandExecution()
95
    {
96
        $this->server = $this->checkEnv('server', 'ACACHA_FORGE_SERVER');
97
        $this->domain = $this->checkEnv('domain', 'ACACHA_FORGE_DOMAIN');
98
99
        if (! File::exists($this->localPath = base_path('.env.production'))) {
100
            $this->error('File ' . $this->localPath . ' not found!');
101
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method abortCommandExecution() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
102
        }
103
104
        $this->abortIfNoSSHConnection();
105
    }
106
}
107