Passed
Push — master ( a30145...bc128f )
by Webysther
36s
created

Base::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Packagist Mirror.
7
 *
8
 * For the full license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webs\Mirror\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Webs\Mirror\ShortName;
19
use Webs\Mirror\IProgressBar;
20
use Webs\Mirror\Filesystem;
21
use Webs\Mirror\Http;
22
use Webs\Mirror\Provider;
23
use Webs\Mirror\Package;
24
25
/**
26
 * Base command.
27
 *
28
 * @author Webysther Nunes <[email protected]>
29
 */
30
class Base extends Command
31
{
32
    use ShortName;
33
34
    /**
35
     * @var bool
36
     */
37
    protected $initialized = false;
38
39
    /**
40
     * @var InputInterface
41
     */
42
    protected $input;
43
44
    /**
45
     * @var OutputInterface
46
     */
47
    protected $output;
48
49
    /**
50
     * @var IProgressBar
51
     */
52
    protected $progressBar;
53
54
    /**
55
     * @var Filesystem
56
     */
57
    protected $filesystem;
58
59
    /**
60
     * @var Http
61
     */
62
    protected $http;
63
64
    /**
65
     * @var Provider
66
     */
67
    protected $provider;
68
69
    /**
70
     * @var Package
71
     */
72
    protected $package;
73
74
    /**
75
     * @var int
76
     */
77
    protected $exitCode;
78
79
    /**
80
     * @var bool
81
     */
82
    protected $verboseVerbose = false;
83
84
    /**
85
     * @var int
86
     */
87
    const VV = OutputInterface::VERBOSITY_VERBOSE;
88
89
    /**
90
     * Main files.
91
     */
92
    const MAIN = 'packages.json';
93
    const DOT = '.packages.json';
94
    const INIT = '.init';
95
    const TO = 'p';
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    protected function configure()
101
    {
102
        $this->addOption(
103
            'no-progress',
104
            null,
105
            InputOption::VALUE_NONE,
106
            "Don't show progress bar"
107
        );
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    protected function initialize(InputInterface $input, OutputInterface $output)
114
    {
115
        $this->input = $input;
116
        $this->output = $output;
117
        $this->verboseVerbose = $this->output->getVerbosity() >= self::VV;
118
    }
119
120
    /**
121
     * @return bool
122
     */
123
    public function isVerbose():bool
124
    {
125
        return $this->verboseVerbose;
126
    }
127
128
    /**
129
     * Add a progress bar.
130
     *
131
     * @param IProgressBar $progressBar
132
     *
133
     * @return Base
134
     */
135
    public function setProgressBar(IProgressBar $progressBar):Base
136
    {
137
        $this->progressBar = $progressBar;
138
139
        return $this;
140
    }
141
142
    /**
143
     * Add a fileSystem.
144
     *
145
     * @param Filesystem $fileSystem
146
     *
147
     * @return Base
148
     */
149
    public function setFilesystem(Filesystem $filesystem):Base
150
    {
151
        $this->filesystem = $filesystem;
152
153
        return $this;
154
    }
155
156
    /**
157
     * Add a http.
158
     *
159
     * @param Http $http
160
     *
161
     * @return Base
162
     */
163
    public function setHttp(Http $http):Base
164
    {
165
        $this->http = $http;
166
167
        return $this;
168
    }
169
170
    /**
171
     * Add a provider.
172
     *
173
     * @param Provider $provider
174
     *
175
     * @return Base
176
     */
177
    public function setProvider(Provider $provider):Base
178
    {
179
        $this->provider = $provider;
180
181
        return $this;
182
    }
183
184
    /**
185
     * Add a packages.
186
     *
187
     * @param Package $package
188
     *
189
     * @return Base
190
     */
191
    public function setPackage(Package $package):Base
192
    {
193
        $this->package = $package;
194
195
        return $this;
196
    }
197
198
    /**
199
     * @param int $exit
200
     *
201
     * @return Base
202
     */
203
    protected function setExitCode(int $exit):Base
204
    {
205
        $this->exitCode = $exit;
206
207
        return $this;
208
    }
209
210
    /**
211
     * @return int
212
     */
213
    protected function getExitCode():int
214
    {
215
        return $this->stop() ? $this->exitCode : 0;
216
    }
217
218
    /**
219
     * @return bool
220
     */
221
    protected function stop():bool
222
    {
223
        return isset($this->exitCode);
224
    }
225
}
226