Completed
Push — master ( c64831...624637 )
by Adam
03:36
created

Git::getGitExecutable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
4
namespace Genesis\Commands;
5
6
7
/**
8
 * @author Adam Bisek <[email protected]>
9
 */
10
class Git extends Command
11
{
12
13
	/** @var string */
14
	private $gitExecutable = 'git';
15
16
	private $command;
17
18
19
	/**
20
	 * @return string
21
	 */
22 1
	public function getGitExecutable()
23
	{
24 1
		return $this->gitExecutable;
25
	}
26
27
28
	/**
29
	 * @param string $gitExecutable
30
	 */
31 2
	public function setGitExecutable($gitExecutable)
32
	{
33 2
		if ($gitExecutable == '') {
34 1
			throw new \InvalidArgumentException("Git executable cannot be empty.");
35
		}
36 1
		$this->gitExecutable = $gitExecutable;
37 1
	}
38
39
40
	/**
41
	 * @return mixed
42
	 */
43 1
	public function getCommand()
44
	{
45 1
		return $this->command;
46
	}
47
48
49
	/**
50
	 * @param mixed $command
51
	 */
52 2
	public function setCommand($command)
53
	{
54 2
		$this->command = $command;
55 2
	}
56
57
58
	public function cloneRepo($url, $branch = NULL, $dir = NULL)
59
	{
60
		$command = escapeshellarg($this->gitExecutable) . " clone";
61
		$command .= " --depth 1 --recursive $url";
62
		$command .= ($branch ? " --branch $branch" : '');
63
		$command .= ($dir ? ' ' . escapeshellarg($dir) : '');
64
		$this->setCommand($command);
65
	}
66
67
68 1
	public function execute()
69
	{
70 1
		return $this->exec(escapeshellarg($this->gitExecutable) . ' ' . $this->command);
71
	}
72
73
74 1
	private function exec($command)
75
	{
76 1
		$exec = new Exec();
77 1
		$exec->setCommand($command);
78 1
		return $exec->execute();
79
	}
80
81
}