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

StaticConstructors   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withMessage() 0 6 1
A withCode() 0 6 1
A andMessage() 0 5 1
A andCode() 0 5 1
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
}