Completed
Push — master ( c8ce79...6ffbf3 )
by Adam
03:48 queued 12s
created

Git   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 72%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 72
ccs 18
cts 25
cp 0.72
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setCommand() 0 4 1
A cloneRepo() 0 8 3
A execute() 0 4 1
A exec() 0 6 1
A getGitExecutable() 0 4 1
A setGitExecutable() 0 7 2
A getCommand() 0 4 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
}