Passed
Push — master ( 5e712b...61b36a )
by Tom
02:52
created

Vcs::getTopLevelDirectory()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Cli;
6
7
/**
8
 * VCS adapter - default implementation is Git
9
 *
10
 * @codeCoverageIgnore
11
 */
12
class Vcs
13
{
14
    /**
15
     * @var Exec
16
     */
17
    private $exec;
18
19
    public function __construct(Exec $exec)
20
    {
21
        $this->exec = $exec;
22
    }
23
24
    /**
25
     * @return null|string
26
     */
27
    public function getTopLevelDirectory()
28
    {
29
        $result = $this->exec->capture('git', array('rev-parse', '--show-toplevel'), $out);
30
        if ($result !== 0) {
31
            return null;
32
        }
33
34
        $path = substr($out, 0,-1);
35
36
        if (!is_dir($path)) {
37
            return null;
38
        }
39
40
        return $path;
41
    }
42
}
43