Completed
Pull Request — develop (#109)
by
unknown
03:28
created

GitBinary::__construct()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.128

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 8
cts 10
cp 0.8
rs 9.2
cc 4
eloc 7
nc 5
nop 1
crap 4.128
1
<?php
2
/**
3
 * GitElephant - An abstraction layer for git written in PHP
4
 * Copyright (C) 2013  Matteo Giachino
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
18
 */
19
20
namespace GitElephant;
21
22
use \GitElephant\Utilities;
23
24
/**
25
 * Git binary
26
 * It contains the reference to the system git binary
27
 *
28
 * @author Matteo Giachino <[email protected]>
29
 */
30
class GitBinary
31
{
32
    /**
33
     * the path to the repository
34
     *
35
     * @var string $path
36
     */
37
    private $path;
38
39
    /**
40
     * Class constructor
41
     *
42
     * @param null $path the physical path to the git binary
43
     */
44 103
    public function __construct($path = null)
45
    {
46 103
        if (is_null($path)) {
47 102
        	$cmd = (Utilities::isWindows() ? "where" : "which") . " git";
48 102
            $path = exec($cmd);
49
50
	        // Escape spaces in the binary path for windows
51 102
	        if(Utilities::isWindows()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
52
		        $path = '"'.$path.'"';
53
	        }
54 102
        }
55 103
        $this->setPath($path);
56 103
    }
57
58
    /**
59
     * path getter
60
     * returns the path of the binary
61
     *
62
     * @return mixed
63
     */
64 99
    public function getPath()
65
    {
66 99
        return $this->path;
67
    }
68
69
    /**
70
     * path setter
71
     *
72
     * @param string $path the path to the system git binary
73
     */
74 103
    public function setPath($path)
75
    {
76 103
        $this->path = $path;
77 103
    }
78
}
79