PublishRc   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 20 3
A getStubPath() 0 4 1
1
<?php
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Compiler\RCFileCompiler;
6
use Acacha\ForgePublish\ForgePublishRCFile;
7
use Illuminate\Console\Command;
8
9
/**
10
 * Class PublishRc.
11
 *
12
 * @package Acacha\ForgePublish\Commands
13
 */
14
class PublishRc extends Command
15
{
16
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'publish:rc {domain_suffix?} {ssh_shell?} ';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Create Forge publish rc (~/.forgepublishrc) config file';
30
31
    /**
32
     * Compiler for llumrc file.
33
     *
34
     * @var RCFileCompiler
35
     */
36
    protected $compiler;
37
38
    /**
39
     * Constructor.
40
     *
41
     */
42
    public function __construct(RCFileCompiler $compiler)
43
    {
44
        parent::__construct();
45
        $this->compiler = $compiler;
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     */
52
    public function handle()
53
    {
54
        $domain_suffix = $this->argument('domain_suffix') ?
55
            $this->argument('domain_suffix') :
56
            $this->ask('Default domain suffix?');
57
58
        $ssh_shell = $this->argument('ssh_shell') ?
59
            $this->argument('ssh_shell') :
60
            $this->choice('Shell to use in SSH?', ['bash','zsh'], 0);
61
62
        $data = [
63
            "ACACHA_FORGE_PUBLISH_DOMAIN_PREFIX" => $domain_suffix,
64
            "ACACHA_FORGE_PUBLISH_SSH_SHELL" => $ssh_shell,
65
        ];
66
67
        $content = $this->compiler->compile(
68
            file_get_contents($this->getStubPath()),
69
            $data);
70
        return file_put_contents(ForgePublishRCFile::path(), $content);
71
    }
72
73
    /**
74
     * Get path to stub.
75
     *
76
     * @return string
77
     */
78
    protected function getStubPath()
79
    {
80
        return __DIR__ . '/stubs/forgepublishrc.stub';
81
    }
82
}
83