Passed
Push — master ( 28f242...472b4c )
by Gabriel
04:44
created

HasCommandPathTrait::getCommandPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\Migrations\Utility\Traits;
4
5
/**
6
 * Trait HasCommandPathTrait
7
 * @package ByTIC\Migrations\Utility\Traits
8
 */
9
trait HasCommandPathTrait
10
{
11
    /**
12
     * @var null|string
13
     */
14
    protected static $commandPath = null;
15
16
    /**
17
     * @return null|string
18
     */
19 1
    public static function getCommandPath()
20
    {
21 1
        if (static::$commandPath === null) {
22 1
            static::$commandPath = static::detectCommandPath();
23
        }
24 1
        return static::$commandPath;
25
    }
26
27
    /**
28
     * @param string|null $path
29
     */
30
    public static function setCommandPath($path)
31
    {
32
        self::$commandPath = $path;
33
    }
34
35
    /**
36
     * @return null|string
37
     */
38 1
    protected static function detectCommandPath()
39
    {
40
        $paths = [
41 1
            static::normalizePath(static::getBasePath(),'vendor','bin','phinx'),
42 1
            '~/.composer/vendor/bin/phinx'
43
        ];
44 1
        foreach ($paths as $path) {
45 1
            if (file_exists($path)) {
46 1
                return $path;
47
            }
48
        }
49
        return null;
50
    }
51
}
52