Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
FlowException | |
0.00% |
0 / 9 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getErrorCode | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getErrorCodeList | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Exception; |
4 | |
5 | use Exception; |
6 | use MessageSpecifier; |
7 | |
8 | /** |
9 | * Flow base exception |
10 | */ |
11 | class FlowException extends Exception implements MessageSpecifier { |
12 | |
13 | /** |
14 | * Flow exception error code |
15 | * @var string |
16 | */ |
17 | protected $code; |
18 | |
19 | /** |
20 | * @param string $message The message from exception, used for debugging error |
21 | * @param string $code The error code used to display error message |
22 | */ |
23 | public function __construct( $message, $code = 'default' ) { |
24 | parent::__construct( $message ); |
25 | $this->code = $code; |
26 | } |
27 | |
28 | /** |
29 | * Get the message key for the localized error message |
30 | * @return string |
31 | */ |
32 | final public function getErrorCode() { |
33 | $list = $this->getErrorCodeList(); |
34 | if ( !in_array( $this->code, $list ) ) { |
35 | $this->code = 'default'; |
36 | } |
37 | return 'flow-error-' . $this->code; |
38 | } |
39 | |
40 | /** |
41 | * Error code list for this exception |
42 | * @return string[] |
43 | */ |
44 | protected function getErrorCodeList() { |
45 | // flow-error-default |
46 | return [ 'default' ]; |
47 | } |
48 | |
49 | /** |
50 | * Implement MessageSpecifier interface to add a more human-friendly error message. |
51 | * @inheritDoc |
52 | */ |
53 | final public function getKey() { |
54 | return $this->getErrorCode(); |
55 | } |
56 | |
57 | /** |
58 | * Implement MessageSpecifier interface to add a more human-friendly error message. |
59 | * @inheritDoc |
60 | */ |
61 | final public function getParams() { |
62 | return []; |
63 | } |
64 | |
65 | } |