Completed
Push — master ( 0ab984...c72dd5 )
by Théo
02:46
created

functions.php ➔ get_version()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 0
cts 0
cp 0
crap 6
rs 9.4285
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;
16
17
use Humbug\PhpScoper\Console\Application;
18
use Humbug\PhpScoper\Console\Command\AddPrefixCommand;
19
use Humbug\PhpScoper\Handler\HandleAddPrefix;
20
use PackageVersions\Versions;
21
use PhpParser\Parser;
22
use PhpParser\ParserFactory;
23
use Symfony\Component\Console\Application as SymfonyApplication;
24
25
/**
26
 * @private
27
 */
28
function create_application(): SymfonyApplication
29
{
30
    $app = new Application('PHP Scoper', get_version());
31
32
    $app->addCommands([
33
        new AddPrefixCommand(
34
            new HandleAddPrefix(
35
                new Scoper(
36
                    create_parser()
37
                )
38
            )
39
        ),
40
    ]);
41
42
    return $app;
43
}
44
45
/**
46
 * @private
47
 */
48
function get_version(): string
49
{
50
    $rawVersion = Versions::getVersion('humbug/php-scoper');
51
52
    list($prettyVersion, $commitHash) = explode('@', $rawVersion);
53
54
    return (1 === preg_match('/9{7}/', $prettyVersion)) ? $commitHash : $prettyVersion;
55
}
56
57
/**
58
 * @private
59
 */
60
function create_parser(): Parser
61
{
62
    return (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
63
}
64