PublishConnect::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\RunsSSHCommands;
7
use Acacha\ForgePublish\Parser\ForgePublishRCParser;
8
use GuzzleHttp\Client;
9
use Illuminate\Console\Command;
10
11
/**
12
 * Class PublishConnect.
13
 *
14
 * @package Acacha\ForgePublish\Commands
15
 */
16
class PublishConnect extends Command
17
{
18
    use RunsSSHCommands, ChecksEnv;
19
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'publish:connect {--server=} {--domain=}';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Connect to server via SSH';
33
34
    /**
35
     * ForgePublishRCParser
36
     *
37
     * @var ForgePublishRCParser
38
     */
39
    protected $parser;
40
41
    /**
42
     * Forge server.
43
     *
44
     * @var String
45
     */
46
    protected $server;
47
48
    /**
49
     * Domain.
50
     *
51
     * @var String
52
     */
53
    protected $domain;
54
55
    /**
56
     * Guzzle http client.
57
     *
58
     * @var Client
59
     */
60
    protected $http;
61
62
    /**
63
     * Create a new command instance.
64
     *
65
     */
66
    public function __construct(Client $http, ForgePublishRCParser $parser)
67
    {
68
        parent::__construct();
69
        $this->http = $http;
70
        $this->parser = $parser;
71
    }
72
73
    /**
74
     * Execute the console command.
75
     *
76
     */
77
    public function handle()
78
    {
79
        $this->abortCommandExecution();
80
        $this->info("Connecting to server $this->server");
81
        $this->runSSH("cd $this->domain;" . $this->defaultShell());
82
    }
83
84
    /**
85
     * Abort command execution.
86
     *
87
     */
88
    protected function abortCommandExecution()
89
    {
90
        $this->server = $this->checkEnv('server', 'ACACHA_FORGE_SERVER');
91
        $this->domain = $this->checkEnv('domain', 'ACACHA_FORGE_DOMAIN');
92
    }
93
94
    /**
95
     * Default Shell.
96
     *
97
     * @return string
98
     */
99
    protected function defaultShell()
100
    {
101
        if ($this->parser->getDefaultShell() == '') {
102
            return 'bash';
103
        }
104
        return $this->parser->getDefaultShell();
105
    }
106
}
107