Programs::execute()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5.0061

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 15
cts 16
cp 0.9375
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 8
nop 0
crap 5.0061
1
<?php
2
3
4
namespace Genesis\Commands\Test;
5
6
7
use Genesis\Commands\Command;
8
9
/**
10
 * @author Adam Bisek <[email protected]>
11
 */
12
class Programs extends Command
13
{
14
15
	private $requiredPrograms;
16
17
18
	/**
19
	 * @return array
20
	 */
21
	public function getRequiredPrograms()
22
	{
23
		return $this->requiredPrograms;
24
	}
25
26
27
	/**
28
	 * @param array $requiredPrograms
29
	 */
30 2
	public function setRequiredPrograms($requiredPrograms)
31
	{
32 2
		$this->requiredPrograms = $requiredPrograms;
33 2
	}
34
35
36 2
	public function execute()
37
	{
38 2
		$errors = array();
39 2
		foreach ($this->requiredPrograms as $program => $howToInstallCommand) {
40 2
			exec('command -v ' . escapeshellarg($program) . ' >/dev/null 2>&1', $output, $return);
41 2
			if ($return !== 0) {
42 1
				$errors[] = 'Required program "' . $program . '" is not installed.';
43 1
				if ($howToInstallCommand) {
44 1
					$errors[] = 'You can fix this by running: ' . $howToInstallCommand;
45 1
				}
46 1
			}
47 2
		}
48
49 2
		if (!empty($errors)) {
50 1
			$this->error(implode(PHP_EOL, $errors));
51
		}
52
53 1
		$this->log('Required programs are installed.');
54 1
	}
55
56
}
57