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

HasCommandPathTrait::detectCommandPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
crap 3.0261
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