Completed
Push — master ( 01982b...3c7394 )
by ANTHONIUS
11s
created

Application::run()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 8
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;
15
16
use Dotfiles\Core\Config\Config;
17
use Symfony\Component\Console\Application as BaseApplication;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Input\StringInput;
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 Config
33
     */
34
    private $config;
35
36
    /**
37
     * @var InputInterface
38
     */
39
    private $input;
40
41
    /**
42
     * @var OutputInterface
43
     */
44
    private $output;
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function __construct(
50
        Config $config,
51
        InputInterface $input,
52
        OutputInterface $output
53
    ) {
54
        parent::__construct('dotfiles', static::VERSION);
55
56
        $this->config = $config;
57
        $this->input = $input;
58
        $this->output = $output;
59
60
        $this->getDefinition()->addOption(
61
            new InputOption('dry-run', '-d', InputOption::VALUE_NONE, 'Only show which files would have been modified')
62
        );
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getLongVersion()
69
    {
70
        return implode(' ', array(
71
            static::VERSION,
72
            static::BRANCH_ALIAS_VERSION,
73
            static::RELEASE_DATE,
74
        ));
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function run(InputInterface $input = null, OutputInterface $output = null)
81
    {
82
        if (null === $input) {
83
            $input = $this->input;
84
        }
85
        if (null === $output) {
86
            $output = $this->output;
87
        }
88
89
        $dryRun = $input->hasParameterOption(array('--dry-run'), true);
90
        $this->config->set('dotfiles.dry_run', $dryRun);
91
92
        if (!getenv('DOTFILES_REPO_DIR') && ('dev' !== getenv('DOTFILES_ENV'))) {
93
            $input = new StringInput('init');
94
        }
95
96
        return parent::run($input, $output);
97
    }
98
}
99