Issues (197)

src/Commands/InstallCommand.php (5 issues)

Labels
Severity
1
<?php
2
3
namespace Salah3id\Domains\Commands;
4
5
use Illuminate\Console\Command;
6
use Salah3id\Domains\Json;
7
use Salah3id\Domains\Process\Installer;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class InstallCommand extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'domain:install';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Install the specified domain by given package name (vendor/name).';
26
27
    /**
28
     * Create a new command instance.
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     */
38
    public function handle(): int
39
    {
40
        if (is_null($this->argument('name'))) {
41
            return $this->installFromFile();
42
        }
43
44
        $this->install(
45
            $this->argument('name'),
0 ignored issues
show
It seems like $this->argument('name') can also be of type array; however, parameter $name of Salah3id\Domains\Command...stallCommand::install() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            /** @scrutinizer ignore-type */ $this->argument('name'),
Loading history...
46
            $this->argument('version'),
0 ignored issues
show
It seems like $this->argument('version') can also be of type array; however, parameter $version of Salah3id\Domains\Command...stallCommand::install() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
            /** @scrutinizer ignore-type */ $this->argument('version'),
Loading history...
47
            $this->option('type'),
0 ignored issues
show
It seems like $this->option('type') can also be of type array; however, parameter $type of Salah3id\Domains\Command...stallCommand::install() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
            /** @scrutinizer ignore-type */ $this->option('type'),
Loading history...
48
            $this->option('tree')
49
        );
50
51
        return 0;
52
    }
53
54
    /**
55
     * Install domains from domains.json file.
56
     */
57
    protected function installFromFile(): int
58
    {
59
        if (!file_exists($path = base_path('domains.json'))) {
60
            $this->error("File 'domains.json' does not exist in your project root.");
61
62
            return E_ERROR;
63
        }
64
65
        $domains = Json::make($path);
66
67
        $dependencies = $domains->get('require', []);
68
69
        foreach ($dependencies as $domain) {
70
            $domain = collect($domain);
71
72
            $this->install(
73
                $domain->get('name'),
74
                $domain->get('version'),
75
                $domain->get('type')
76
            );
77
        }
78
79
        return 0;
80
    }
81
82
    /**
83
     * Install the specified domain.
84
     *
85
     * @param string $name
86
     * @param string $version
87
     * @param string $type
88
     * @param bool   $tree
89
     */
90
    protected function install($name, $version = 'dev-master', $type = 'composer', $tree = false)
91
    {
92
        $installer = new Installer(
93
            $name,
94
            $version,
95
            $type ?: $this->option('type'),
0 ignored issues
show
It seems like $type ?: $this->option('type') can also be of type array; however, parameter $type of Salah3id\Domains\Process\Installer::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
            /** @scrutinizer ignore-type */ $type ?: $this->option('type'),
Loading history...
96
            $tree ?: $this->option('tree')
97
        );
98
99
        $installer->setRepository($this->laravel['domains']);
100
101
        $installer->setConsole($this);
102
103
        if ($timeout = $this->option('timeout')) {
104
            $installer->setTimeout($timeout);
0 ignored issues
show
$timeout of type array|string|true is incompatible with the type integer expected by parameter $timeout of Salah3id\Domains\Process\Installer::setTimeout(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
            $installer->setTimeout(/** @scrutinizer ignore-type */ $timeout);
Loading history...
105
        }
106
107
        if ($path = $this->option('path')) {
108
            $installer->setPath($path);
109
        }
110
111
        $installer->run();
112
113
        if (!$this->option('no-update')) {
114
            $this->call('domain:update', [
115
                'domain' => $installer->getDomainName(),
116
            ]);
117
        }
118
    }
119
120
    /**
121
     * Get the console command arguments.
122
     *
123
     * @return array
124
     */
125
    protected function getArguments()
126
    {
127
        return [
128
            ['name', InputArgument::OPTIONAL, 'The name of domain will be installed.'],
129
            ['version', InputArgument::OPTIONAL, 'The version of domain will be installed.'],
130
        ];
131
    }
132
133
    /**
134
     * Get the console command options.
135
     *
136
     * @return array
137
     */
138
    protected function getOptions()
139
    {
140
        return [
141
            ['timeout', null, InputOption::VALUE_OPTIONAL, 'The process timeout.', null],
142
            ['path', null, InputOption::VALUE_OPTIONAL, 'The installation path.', null],
143
            ['type', null, InputOption::VALUE_OPTIONAL, 'The type of installation.', null],
144
            ['tree', null, InputOption::VALUE_NONE, 'Install the domain as a git subtree', null],
145
            ['no-update', null, InputOption::VALUE_NONE, 'Disables the automatic update of the dependencies.', null],
146
        ];
147
    }
148
}
149