Passed
Push — master ( 6015fa...83e3bb )
by Tom
02:48
created

StatusException::__construct()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 2
nop 3
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Utility;
6
7
use Exception;
8
9
/**
10
 * Signal utility exit status, optionally with an (error) message
11
 */
12
class StatusException extends Exception
13
{
14 6
    public function __construct($message = "", $code = 0, Exception $previous = null)
15
    {
16 6
        if (!is_int($code) || $code < 0 || $code > 255) {
17 2
            throw new \InvalidArgumentException(
18 2
                sprintf(
19 2
                    'Code must be integer in range from 0 to 255, %s given',
20 2
                    var_export($code, true)
21
                )
22
            );
23
        }
24
25 4
        parent::__construct($message, $code, $previous);
26 4
    }
27
    /**
28
     * @param int $code
29
     * @param string $message
30
     * @throws StatusException
31
     */
32 1
    public static function status($code = 0, $message = "")
33
    {
34 1
        throw new self($message, $code);
35
    }
36
}
37