Completed
Pull Request — master (#9)
by Matthias
02:27
created

Application   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getPackageVersion() 0 21 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: matthias
5
 * Date: 28.11.15
6
 * Time: 23:49
7
 */
8
9
namespace ComposerRequireChecker\Cli;
10
use Symfony\Component\Console\Application as AbstractApplication;
11
12
class Application extends AbstractApplication
13
{
14
15
    public function __construct()
16
    {
17
        parent::__construct('ComposerRequireChecker', $this->getPackageVersion());
18
19
        $check = new CheckCommand();
20
        $this->add($check);
21
        $this->setDefaultCommand($check->getName());
22
    }
23
24
    private function getPackageVersion() : string
25
    {
26
        $version = null;
27
        $pharFile = \Phar::running();
28
        if($pharFile) {
29
            $metadata = (new \Phar($pharFile))->getMetadata();
30
            $version = $metadata['version'] ?? null;
31
        }
32
33
        if(!$version) {
34
            $pwd = getcwd();
35
            chdir(realpath(__DIR__ . '/../../../'));
36
            $gitVersion = @exec('git describe --tags --dirty=-dev --always 2>&1', $output, $returnValue);
37
            chdir($pwd);
38
            if($returnValue === 0) {
39
                $version = $gitVersion;
40
            }
41
        }
42
43
        return $version ?? 'unknown-development';
44
    }
45
46
}