Passed
Pull Request — master (#480)
by Théo
02:11
created

Application::getHelp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\Console;
16
17
use Fidry\Console\Application\Application as FidryApplication;
18
use Fidry\Console\Command\Command;
19
use Humbug\PhpScoper\Console\Command\AddPrefixCommand;
20
use Humbug\PhpScoper\Console\Command\InitCommand;
21
use Humbug\PhpScoper\Container;
22
use Symfony\Component\Console\Application as SymfonyApplication;
23
use Symfony\Component\Console\Helper\FormatterHelper;
24
use Symfony\Component\Filesystem\Filesystem;
25
use function Humbug\PhpScoper\get_php_scoper_version;
26
use function Safe\sprintf;
27
use function strpos;
28
use function trim;
29
30
final class Application implements FidryApplication
31
{
32
    private const LOGO = <<<'ASCII'
33
34
    ____  __  ______     _____
35
   / __ \/ / / / __ \   / ___/_________  ____  ___  _____
36
  / /_/ / /_/ / /_/ /   \__ \/ ___/ __ \/ __ \/ _ \/ ___/
37
 / ____/ __  / ____/   ___/ / /__/ /_/ / /_/ /  __/ /
38
/_/   /_/ /_/_/       /____/\___/\____/ .___/\___/_/
39
                                     /_/
40
41
42
ASCII;
43
44
    private const RELEASE_DATE_PLACEHOLDER = '@release-date@';
45
46
    private Container $container;
47
    private string $version;
48
    private string $releaseDate;
49
    private bool $isAutoExitEnabled;
50
    private bool $areExceptionsCaught;
51
52
    public static function create(): self
53
    {
54
        return new self(
55
            new Container(),
56
            get_php_scoper_version(),
57
            false === strpos(self::RELEASE_DATE_PLACEHOLDER, '@')
58
                ? self::RELEASE_DATE_PLACEHOLDER
59
                : '',
60
            true,
61
            true,
62
        );
63
    }
64
65
    public function __construct(
66
        Container $container,
67
        string $version,
68
        string $releaseDate,
69
        bool $isAutoExitEnabled,
70
        bool $areExceptionsCaught
71
    ) {
72
        $this->container = $container;
73
        $this->version = $version;
74
        $this->releaseDate = $releaseDate;
75
        $this->isAutoExitEnabled = $isAutoExitEnabled;
76
        $this->areExceptionsCaught = $areExceptionsCaught;
77
    }
78
79
    public function getName(): string
80
    {
81
        return 'PhpScoper';
82
    }
83
84
    public function getVersion(): string
85
    {
86
        return $this->version;
87
    }
88
89
    public function getLongVersion(): string
90
    {
91
        return trim(
92
            sprintf(
93
                '<info>%s</info> version <comment>%s</comment> %s',
94
                $this->getName(),
95
                $this->getVersion(),
96
                $this->releaseDate
97
            )
98
        );
99
    }
100
101
    public function getHelp(): string
102
    {
103
        return self::LOGO.$this->getLongVersion();
104
    }
105
106
    public function getCommands(): array
107
    {
108
        // TODO: move to the container
109
        $fileSystem = new Filesystem();
110
111
        return [
112
            new AddPrefixCommand(
113
                $fileSystem,
114
                $this->container->getScoper(),
115
            ),
116
            new InitCommand(
117
                $fileSystem,
118
                new FormatterHelper(),
119
            ),
120
        ];
121
    }
122
123
    public function getDefaultCommand(): string
124
    {
125
        return 'list';
126
    }
127
128
    public function isAutoExitEnabled(): bool
129
    {
130
        return $this->isAutoExitEnabled;
131
    }
132
133
    public function areExceptionsCaught(): bool
134
    {
135
        return $this->areExceptionsCaught;
136
    }
137
}
138