Passed
Pull Request — master (#48)
by Théo
02:13
created

Application::getLongVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Console;
16
17
use Humbug\SelfUpdate\Exception\RuntimeException as SelfUpdateRuntimeException;
18
use Humbug\SelfUpdate\Updater;
19
use KevinGH\Box\Console\Command\SelfUpdateCommand;
20
use Symfony\Component\Console\Application as SymfonyApplication;
21
use Symfony\Component\Console\Helper\HelperSet;
22
23
final class Application extends SymfonyApplication
24
{
25
    private const LOGO = <<<'ASCII'
26
27
    ____            
28
   / __ )____  _  __
29
  / __  / __ \| |/_/
30
 / /_/ / /_/ />  <  
31
/_____/\____/_/|_|  
32
                    
33
34
35
ASCII;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function __construct(string $name = 'Box', string $version = '@git-version@')
41
    {
42
        parent::__construct($name, $version);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getLongVersion()
49
    {
50
        if (('@'.'git-version@') !== $this->getVersion()) {
51
            return sprintf(
52
                '<info>%s</info> version <comment>%s</comment> build <comment>%s</comment>',
53
                $this->getName(),
54
                $this->getVersion(),
55
                '@git-commit@'
56
            );
57
        }
58
59
        return '<info>'.$this->getName().'</info> (repo)';
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getHelp(): string
66
    {
67
        return self::LOGO.parent::getHelp();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function getDefaultCommands(): array
74
    {
75
        $commands = parent::getDefaultCommands();
76
77
        $commands[] = new Command\Build();
78
        $commands[] = new Command\Info();
79
        $commands[] = new Command\Validate();
80
        $commands[] = new Command\Verify();
81
82
        if ('phar:' === substr(__FILE__, 0, 5)) {
83
            try {
84
                $updater = new Updater();
85
            } catch (SelfUpdateRuntimeException $e) {
86
                // Allow E2E testing of unsigned phar
87
                $updater = new Updater(null, false);
88
            }
89
            $commands[] = new SelfUpdateCommand($updater);
90
        }
91
92
        return $commands;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    protected function getDefaultHelperSet(): HelperSet
99
    {
100
        $helperSet = parent::getDefaultHelperSet();
101
        $helperSet->set(new \KevinGH\Box\Console\ConfigurationHelper());
102
103
        return $helperSet;
104
    }
105
}
106