ProcessHelper::execute()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 3
1
<?php
2
/*
3
 * This file is part of project-quality-inspector.
4
 *
5
 * (c) Alexandre GESLIN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace ProjectQualityInspector\Application;
12
13
class ProcessHelper
14
{
15
    /**
16
     * @param string $command
17
     * @param string $baseDir
18
     * @param boolean $allowErrorExitCode
19
     *
20
     * @return array
21
     *
22
     * @throws \RuntimeException
23
     */
24
    public static function execute($command, $baseDir, $allowErrorExitCode = false)
25
    {
26
        $command = 'cd ' . escapeshellarg($baseDir) . '; ' . $command . ' 2>&1';
27
28
        if (DIRECTORY_SEPARATOR == '/') {
29
            $command = 'LC_ALL=en_US.UTF-8 ' . $command;
30
        }
31
        exec($command, $output, $returnValue);
32
        if ($returnValue !== 0 && !$allowErrorExitCode) {
33
            throw new \RuntimeException(sprintf('ProcessHelper command : %s. Output: %s', $command, implode("\r\n", $output)));
34
        }
35
        return $output;
36
    }
37
}