HasCommandPathTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 41
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setCommandPath() 0 3 1
A detectCommandPath() 0 12 3
A getCommandPath() 0 6 2
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