Passed
Push — master ( 88d9d6...ec4c8d )
by Tom
04:42
created

Vcs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTopLevelDirectory() 0 14 3
A __construct() 0 3 1
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