Completed
Push — master ( 178b4a...1f981d )
by Richard
06:19
created

SourceStatusGit   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 27
ccs 10
cts 11
cp 0.9091
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A commit_hash() 0 9 2
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the licence along with the code.
9
 */
10
11
namespace Lechimp\Dicto\App;
12
13
/**
14
 * Get the current state of the sourcecode by using git.
15
 */
16
class SourceStatusGit implements SourceStatus {
17
    /**
18
     * @var string
19
     */
20
    protected $path;
21
22
    /**
23
     * @param   string  $path
24
     */
25 3
    public function __construct($path) {
26 3
        assert('is_string($path)');
27 3
        $this->path = $path;
28 3
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33 1
    public function commit_hash() {
34 1
        $escaped_path = escapeshellarg($this->path);
35 1
        $command = "git -C $escaped_path rev-parse HEAD";
36 1
        exec($command, $output, $returned);
37 1
        if ($returned != 0) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $returned of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
38
            throw new \RuntimeException(implode("\n", $output));
39
        }
40 1
        return $output[0];
41
    }
42
}
43