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

Process   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 12
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A readFromProcess() 0 19 3
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