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

Command   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

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