Completed
Push — master ( a92ee2...268555 )
by Dmitry
04:05
created

StaticConstructors::andMessage()   A

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\Mixin;
4
5
/**
6
 * Represent static constructors for exceptions.
7
 *
8
 * @property string $message exception message.
9
 * @property int $code exception code.
10
 *
11
 * @author Dmitry Kolodko <[email protected]>
12
 * @since 1.0
13
 */
14
trait StaticConstructors {
15
    public static function withMessage(string $message): self {
16
        $exception = new static();
17
        $exception->message = $message;
18
19
        return $exception;
20
    }
21
22
    public static function withCode(int $code): self {
23
        $exception = new static();
24
        $exception->code = $code;
25
26
        return $exception;
27
    }
28
29
    public function andMessage(string $message): self {
30
        $this->message = $message;
31
32
        return $this;
33
    }
34
35
    public function andCode(int $code): self {
36
        $this->code = $code;
37
38
        return $this;
39
    }
40
}