Completed
Pull Request — master (#9)
by ANTHONIUS
02:55
created

Application::getLongVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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\DI\Parameters;
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\Output\OutputInterface;
21
22
class Application extends BaseApplication
23
{
24
    public const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@';
25
26
    public const RELEASE_DATE = '@release_date@';
27
28
    public const VERSION = '@package_version@';
29
30
    /**
31
     * @var InputInterface
32
     */
33
    private $input;
34
35
    /**
36
     * @var OutputInterface
37
     */
38
    private $output;
39
40
    /**
41
     * @var Parameters
42
     */
43
    private $parameters;
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function __construct(
49
        Parameters $parameters,
50
        InputInterface $input,
51
        OutputInterface $output
52
    ) {
53
        parent::__construct('dotfiles', static::VERSION);
54
55
        $this->parameters = $parameters;
56
        $this->input = $input;
57
        $this->output = $output;
58
59
        $this->getDefinition()->addOption(
60
            new InputOption('dry-run', '-d', InputOption::VALUE_NONE, 'Only show which files would have been modified')
61
        );
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getLongVersion()
68
    {
69
        return implode(' ', array(
70
            static::VERSION,
71
            static::BRANCH_ALIAS_VERSION,
72
            static::RELEASE_DATE,
73
        ));
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     *
79
     * @codeCoverageIgnore
80
     */
81
    public function run(InputInterface $input = null, OutputInterface $output = null)
82
    {
83
        if (null === $input) {
84
            $input = $this->input;
85
        }
86
87
        if (null === $output) {
88
            $output = $this->output;
89
        }
90
91
        /* @codeCoverageIgnoreStart */
92
        if (
93
            !getenv('DOTFILES_BACKUP_DIR')
94
            && ('dev' !== getenv('DOTFILES_ENV'))
95
        ) {
96
            return $this->find('init')->run($input, $output);
97
        }
98
        /* @codeCoverageIgnoreEnd */
99
        $this->setDefaultCommand('shell');
100
101
        return parent::run($input, $output);
102
    }
103
}
104