CommandException::__construct()   A
last analyzed

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
    /**
21
     * CommandException constructor.
22
     *
23
     * @param string $command
24
     * @param string $output
25
     * @param int    $returnCode
26
     */
27
    public function __construct(string $command, string $output, int $returnCode)
28
    {
29
        if ($returnCode == 127) {
30
            $message = 'Command not found: "'.$command.'"';
31
        } else {
32
            $message = 'Command "'.$command.'" exited with code '.$returnCode.': '.$output;
33
        }
34
35
        parent::__construct($message);
36
    }
37
}
38