ExitException::withStatusCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PHPKitchen\Platform\Exception\Runtime\App;
4
5
use PHPKitchen\Platform\Exception\Mixin\StaticConstructors;
6
use Throwable;
7
8
/**
9
 * Represents thrown to terminate application.
10
 *
11
 * Such exception should be caught only by low-level classes that would handle {@link statusCode} and
12
 * terminate the application.
13
 *
14
 * @author Dmitry Kolodko <[email protected]>
15
 * @since 1.0
16
 */
17
class ExitException extends \Exception {
18
    use StaticConstructors;
19
    /**
20
     * @var int the exit status code
21
     */
22
    public $statusCode;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param int $status the exit status code
28
     * @param string $message error message
0 ignored issues
show
Documentation introduced by
Should the type for parameter $message not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
29
     * @param int $code error code
30
     * @param Throwable $previous The previous exception used for the exception chaining.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $previous not be null|Throwable?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
31
     */
32
    public function __construct($status = 0, $message = null, $code = 0, Throwable $previous = null) {
33
        $this->statusCode = $status;
34
        parent::__construct($message, $code, $previous);
35
    }
36
37
    public static function withStatusCode(int $code): self {
38
        $exception = new static($code);
39
40
        return $exception;
41
    }
42
43
    public function getName() {
44
        return 'App Exit';
45
    }
46
47
    public function andStatusCode(int $code): self {
48
        $this->statusCode = $code;
49
50
        return $this;
51
    }
52
}