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 Wikimedia\Message\MessageSpecifier; |
| 6 | |
| 7 | /** |
| 8 | * Flow base exception |
| 9 | */ |
| 10 | class FlowException extends FlowBaseException implements MessageSpecifier { |
| 11 | |
| 12 | /** |
| 13 | * Flow exception error code |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $code; |
| 17 | |
| 18 | /** |
| 19 | * @param string $message The message from exception, used for debugging error, with PSR-3 style placeholders. |
| 20 | * @param string $code The error code used to display error message |
| 21 | * @param array $context Message context, with values for the placeholders. |
| 22 | */ |
| 23 | public function __construct( $message, $code = 'default', $context = [] ) { |
| 24 | parent::__construct( $message, $context ); |
| 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(): string { |
| 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(): array { |
| 62 | return []; |
| 63 | } |
| 64 | |
| 65 | } |