CliScriptDeterminator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A cliExecutable() 0 8 2
A detectCliExecutable() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of tenside/core-bundle.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core-bundle
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core-bundle/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core-bundle
18
 * @filesource
19
 */
20
21
namespace Tenside\CoreBundle\Util;
22
23
/**
24
 * This class provides information about the cli command to use throughout tenside.
25
 */
26
class CliScriptDeterminator
27
{
28
    /**
29
     * The executable to use in non-phar mode.
30
     *
31
     * @var string
32
     */
33
    private $scriptName;
34
35
    /**
36
     * The cached value.
37
     *
38
     * @var string
39
     */
40
    private $cachedValue;
41
42
    /**
43
     * Create a new instance.
44
     *
45
     * @param string $scriptName The executable to use in non-phar mode.
46
     */
47
    public function __construct($scriptName)
48
    {
49
        $this->scriptName = $scriptName;
50
    }
51
52
    /**
53
     * Retrieve the home directory.
54
     *
55
     * @return string
56
     */
57
    public function cliExecutable()
58
    {
59
        if (null !== $this->cachedValue) {
60
            return $this->cachedValue;
61
        }
62
63
        return $this->cachedValue = $this->detectCliExecutable();
64
    }
65
66
    /**
67
     * Determine the correct executable.
68
     *
69
     * @return string
70
     */
71
    private function detectCliExecutable()
72
    {
73
        return \Phar::running(false) ?: $this->scriptName;
74
    }
75
}
76