Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PHPErrorReporter | |
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| reportError | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Rest\Reporter; |
| 4 | |
| 5 | use MediaWiki\Rest\Handler; |
| 6 | use MediaWiki\Rest\RequestInterface; |
| 7 | use Throwable; |
| 8 | |
| 9 | /** |
| 10 | * Error reporter based on php's native trigger_error() method. |
| 11 | * @since 1.38 |
| 12 | */ |
| 13 | class PHPErrorReporter implements ErrorReporter { |
| 14 | |
| 15 | /** @var int */ |
| 16 | private $level; |
| 17 | |
| 18 | /** |
| 19 | * @param int $level The error level to pass to trigger_error |
| 20 | */ |
| 21 | public function __construct( $level = E_USER_WARNING ) { |
| 22 | $this->level = $level; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @param Throwable $error |
| 27 | * @param Handler|null $handler |
| 28 | * @param RequestInterface $request |
| 29 | */ |
| 30 | public function reportError( Throwable $error, ?Handler $handler, RequestInterface $request ) { |
| 31 | $firstLine = preg_split( '#$#m', (string)$error, 0 )[0]; |
| 32 | trigger_error( $firstLine, $this->level ); |
| 33 | } |
| 34 | |
| 35 | } |