Completed
Push — master ( c80037...a80085 )
by Théo
85:09 queued 44:18
created

Application::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 3
dl 0
loc 14
rs 9.7998
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 PackageVersions\Versions;
18
use Symfony\Component\Console\Application as SymfonyApplication;
19
use function trim;
20
21
final class Application extends SymfonyApplication
22
{
23
    private const LOGO = <<<'ASCII'
24
25
    ____  __  ______     _____                           
26
   / __ \/ / / / __ \   / ___/_________  ____  ___  _____
27
  / /_/ / /_/ / /_/ /   \__ \/ ___/ __ \/ __ \/ _ \/ ___/
28
 / ____/ __  / ____/   ___/ / /__/ /_/ / /_/ /  __/ /    
29
/_/   /_/ /_/_/       /____/\___/\____/ .___/\___/_/     
30
                                     /_/
31
32
33
ASCII;
34
35
    private $releaseDate;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function __construct(string $name = 'Box', string $version = null, string $releaseDate = '@release-date@')
41
    {
42
        if (null === $version) {
43
            $rawVersion = Versions::getVersion('humbug/php-scoper');
44
45
            [$prettyVersion, $commitHash] = explode('@', $rawVersion);
2 ignored issues
show
Bug introduced by
The variable $prettyVersion does not exist. Did you mean $version?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
Bug introduced by
The variable $commitHash does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
46
47
            $version = $prettyVersion.'@'.substr($commitHash, 0, 7);
1 ignored issue
show
Bug introduced by
The variable $prettyVersion does not exist. Did you mean $version?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
48
        }
49
50
        $this->releaseDate = false === strpos($releaseDate, '@') ? $releaseDate : '';
51
52
        parent::__construct($name, $version);
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function getLongVersion(): string
59
    {
60
        return trim(
61
            sprintf(
62
                '<info>%s</info> version <comment>%s</comment> %s',
63
                $this->getName(),
64
                $this->getVersion(),
65
                $this->releaseDate
66
            )
67
        );
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function getHelp(): string
74
    {
75
        return self::LOGO.parent::getHelp();
76
    }
77
}
78