Command   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 11
c 0
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 15 3
A getLastCommand() 0 3 1
1
<?php
2
3
namespace Sanchescom\WiFi\System;
4
5
use Sanchescom\WiFi\Contracts\CommandInterface;
6
use Sanchescom\WiFi\Exceptions\CommandException;
7
8
/**
9
 * Class CommandExecutor.
10
 */
11
class Command implements CommandInterface
12
{
13
    /** @var string */
14
    protected $lastCommand;
15
16
    /**
17
     * @param string $command
18
     *
19
     * @return string
20
     */
21
    public function execute(string $command)
22
    {
23
        $command .= ' 2>&1';
24
25
        exec($command, $output, $code);
26
27
        $output = $this->lastCommand = count($output) === 0
28
            ? $code
29
            : implode(PHP_EOL, $output);
30
31
        if ($code !== 0) {
32
            throw new CommandException($command, $output, $code);
33
        }
34
35
        return $output;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getLastCommand()
42
    {
43
        return $this->lastCommand;
44
    }
45
}
46