Passed
Pull Request — master (#9)
by ANTHONIUS
02:22
created

Application::run()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the dotfiles project.
7
 *
8
 *     (c) Anthonius Munthi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Dotfiles\Core\Console;
15
16
use Dotfiles\Core\Command\ShellCommand;
17
use Dotfiles\Core\DI\Parameters;
18
use Symfony\Component\Console\Application as BaseApplication;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
class Application extends BaseApplication
24
{
25
    public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@';
26
27
    public const RELEASE_DATE = '@release_date@';
28
29
    public const VERSION = '@package_version@';
30
31
    /**
32
     * @var InputInterface
33
     */
34
    private $input;
35
36
    /**
37
     * @var OutputInterface
38
     */
39
    private $output;
40
41
    /**
42
     * @var Parameters
43
     */
44
    private $parameters;
45
46
    /**
47
     * @var bool
48
     */
49
    private $shellIsRunning = false;
0 ignored issues
show
introduced by
The private property $shellIsRunning is not used, and could be removed.
Loading history...
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function __construct(
55
        Parameters $parameters,
56
        InputInterface $input,
57
        OutputInterface $output
58
    ) {
59
        parent::__construct('dotfiles', static::VERSION);
60
61
        $this->parameters = $parameters;
62
        $this->input = $input;
63
        $this->output = $output;
64
65
        $this->getDefinition()->addOption(
66
            new InputOption('dry-run', '-d', InputOption::VALUE_NONE, 'Only show which files would have been modified')
67
        );
68
        $this->add(new ShellCommand());
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getLongVersion()
75
    {
76
        return implode(' ', array(
77
            static::VERSION,
78
            static::BRANCH_ALIAS_VERSION,
79
            static::RELEASE_DATE,
80
        ));
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function run(InputInterface $input = null, OutputInterface $output = null)
87
    {
88
        if (
89
            !getenv('DOTFILES_BACKUP_DIR')
90
            && ('dev' !== getenv('DOTFILES_ENV'))
91
        ) {
92
            return $this->find('init')->run($input, $output);
0 ignored issues
show
Bug introduced by
It seems like $input can also be of type null; however, parameter $input of Symfony\Component\Console\Command\Command::run() does only seem to accept Symfony\Component\Console\Input\InputInterface, 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

92
            return $this->find('init')->run(/** @scrutinizer ignore-type */ $input, $output);
Loading history...
Bug introduced by
It seems like $output can also be of type null; however, parameter $output of Symfony\Component\Console\Command\Command::run() does only seem to accept Symfony\Component\Console\Output\OutputInterface, 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

92
            return $this->find('init')->run($input, /** @scrutinizer ignore-type */ $output);
Loading history...
93
        }
94
        $this->setDefaultCommand('shell');
95
96
        return parent::run($input, $output);
97
    }
98
}
99