Passed
Pull Request — master (#5)
by Aleksandr
02:02
created

CommandException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sanchescom\WiFi\Exceptions;
6
7
use RuntimeException;
8
9
/**
10
 * Class CommandException.
11
 */
12
class CommandException extends RuntimeException
13
{
14
    /** @var string */
15
    protected $command;
16
17
    /** @var string */
18
    protected $output;
19
20
    /** @var int */
21
    protected $returnCode;
22
23
    /**
24
     * CommandException constructor.
25
     *
26
     * @param string $command
27
     * @param string $output
28
     * @param int    $returnCode
29
     */
30
    public function __construct(string $command, string $output, int $returnCode)
31
    {
32
        if ($this->returnCode == 127) {
33
            $message = 'Command not found: "'.$command.'"';
34
        } else {
35
            $message = 'Command "'.$command.'" exited with code '.$returnCode.': '.$output;
36
        }
37
38
        parent::__construct($message);
39
    }
40
}
41