Completed
Push — master ( ce7873...f081a5 )
by Aleksandr
16s queued 10s
created

Command::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
namespace Sanchescom\WiFi\System;
4
5
use Sanchescom\WiFi\Exceptions\CommandException;
6
7
/**
8
 * Class CommandExecutor.
9
 */
10
class Command
11
{
12
    /**
13
     * @param string $command
14
     *
15
     * @return string
16
     */
17
    public function execute(string $command)
18
    {
19
        $command .= ' 2>&1';
20
21
        exec($command, $output, $code);
22
23
        $output = count($output) === 0
24
            ? $code
25
            : implode(PHP_EOL, $output);
26
27
        if ($code !== 0) {
28
            throw new CommandException($command, $output, $code);
29
        }
30
31
        return $output;
32
    }
33
}
34