Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
PhonosException | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getMessageKeyAndArgs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStatsdKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Phonos\Exception; |
4 | |
5 | use Exception; |
6 | |
7 | /** |
8 | * Exception thrown when something within Phonos failed. |
9 | * @newable |
10 | */ |
11 | class PhonosException extends Exception { |
12 | |
13 | private array $args; |
14 | |
15 | /** |
16 | * @param string $message Message key of error message. |
17 | * @param array $args Parameters to pass to the message. |
18 | */ |
19 | public function __construct( string $message, array $args = [] ) { |
20 | parent::__construct( $message ); |
21 | $this->args = $args; |
22 | } |
23 | |
24 | /** |
25 | * Returns array with exception message key and parameters. |
26 | * |
27 | * @return array |
28 | */ |
29 | public function getMessageKeyAndArgs(): array { |
30 | return [ $this->getMessage(), ...$this->args ]; |
31 | } |
32 | |
33 | /** |
34 | * Key for use in statsd metrics, where hyphens aren't allowed. |
35 | * |
36 | * @return string |
37 | */ |
38 | public function getStatsdKey(): string { |
39 | return str_replace( '-', '_', $this->getMessage() ); |
40 | } |
41 | } |