Passed
Branch master (c65b3c)
by Jan
05:40 queued 01:37
created

Executor::executeCommand()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 17
ccs 0
cts 16
cp 0
rs 9.2
cc 4
eloc 12
nc 8
nop 2
crap 20
1
<?php
2
3
namespace App;
4
5
class Executor
6
{
7
8
	/**
9
	 * @param string|array $scriptPath
10
	 */
11
	public function executeCommand($scriptPath, array $env)
12
	{
13
		$oldCwd = NULL;
14
		if (is_array($scriptPath)) {
15
			$cwd = $scriptPath['cwd'];
16
			$scriptPath = $scriptPath['command'];
17
			$oldCwd = getcwd();
18
			chdir($cwd);
19
		}
20
		foreach ($env as $key => $value) {
21
			putenv($key . '=' . $value);
22
		}
23
		shell_exec($scriptPath);
24
		if ($oldCwd !== NULL) {
25
			chdir($oldCwd);
26
		}
27
	}
28
29
}
30