Passed
Push — master ( 88d9d6...ec4c8d )
by Tom
04:42
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 10
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
     * @throws \RuntimeException
26
     *
27
     * @return null|string
28
     */
29
    public function getTopLevelDirectory()
30
    {
31
        $result = $this->exec->capture('git', array('rev-parse', '--show-toplevel'), $out);
32
        if (0 !== $result) {
33
            return null;
34
        }
35
36
        $path = substr($out, 0, -1);
37
38
        if (!is_dir($path)) {
39
            return null;
40
        }
41
42
        return $path;
43
    }
44
}
45