Passed
Push — master ( c80f53...a44ccc )
by Pierre
08:34
created

Process::readFromProcess()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 19
ccs 0
cts 12
cp 0
crap 12
rs 9.8333
1
<?php
2
3
namespace App\Component\Console;
4
5
class Process
6
{
7
8
    /**
9
     * return string result for a given system command
10
     *
11
     * @param string $command
12
     * @return string
13
     */
14
    public static function readFromProcess(string $command): string
15
    {
16
        if (!\function_exists('proc_open')) {
17
            return null;
18
        }
19
        $descriptorspec = [
20
            1 => ['pipe', 'w'],
21
            2 => ['pipe', 'w'],
22
        ];
23
        $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => false]);
24
        if (!\is_resource($process)) {
25
            return null;
26
        }
27
        $info = stream_get_contents($pipes[1]);
28
29
        fclose($pipes[1]);
30
        fclose($pipes[2]);
31
        proc_close($process);
32
        return $info;
33
    }
34
}
35