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

SourceStatusGit::commit_hash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
ccs 6
cts 7
cp 0.8571
rs 9.6666
cc 2
eloc 7
nc 2
nop 0
crap 2.0116
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