Passed
Push — master ( 15fbce...c7ecbb )
by Jan
03:02
created

Executor::executeCommand()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 6

Importance

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