Passed
Pull Request — master (#480)
by Théo
11:17 queued 23s
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 12
rs 10
c 0
b 0
f 0
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
        return [
109
            new AddPrefixCommand(
110
                $this->container->getFileSystem(),
111
                $this->container->getScoper(),
112
                $this,
113
            ),
114
            new InitCommand(
115
                $this->container->getFileSystem(),
116
                new FormatterHelper(),
117
            ),
118
        ];
119
    }
120
121
    public function getDefaultCommand(): string
122
    {
123
        return 'list';
124
    }
125
126
    public function isAutoExitEnabled(): bool
127
    {
128
        return $this->isAutoExitEnabled;
129
    }
130
131
    public function areExceptionsCaught(): bool
132
    {
133
        return $this->areExceptionsCaught;
134
    }
135
}
136