Completed
Push — master ( de6ffa...f677f6 )
by Aleksandr
12s queued 11s
created

Command::getLastCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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