Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ErrorException | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFriendlySeverity | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getFriendlyType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
| 5 | */ |
| 6 | |
| 7 | declare(strict_types=1); |
| 8 | |
| 9 | namespace pvc\err\stock; |
| 10 | |
| 11 | use pvc\err\ErrorHandler; |
| 12 | use Throwable; |
| 13 | |
| 14 | /** |
| 15 | * Class ErrorException |
| 16 | */ |
| 17 | class ErrorException extends \ErrorException |
| 18 | { |
| 19 | /** |
| 20 | * As I understand it, 'severity' in the parent constructor is not actually the severity of |
| 21 | * the error type, it is the error type itself. For example, the default of E_ERROR is not |
| 22 | * a severity (notice / warning / etc.) It is the error type. I have maintained the name |
| 23 | * of the dummy parameter to maintain consistency between this class and the parent class. |
| 24 | */ |
| 25 | public function __construct( |
| 26 | string $message = "", |
| 27 | int $code = 0, |
| 28 | int $severity = E_ERROR, |
| 29 | ?string $filename = null, |
| 30 | ?int $line = null, |
| 31 | ?Throwable $previous = null |
| 32 | ) { |
| 33 | parent::__construct($message, $code, $severity, $filename, $line, $previous); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @return string |
| 38 | * returns 'NOTICE', 'WARNING', 'PARSE', 'FATAL' (or undefined) |
| 39 | */ |
| 40 | public function getFriendlySeverity(): string |
| 41 | { |
| 42 | /** |
| 43 | * confusing, but it's not my fault........ |
| 44 | */ |
| 45 | $errorType = $this->getSeverity(); |
| 46 | $severity = ErrorHandler::getErrorSeverity($errorType); |
| 47 | return ErrorHandler::friendlyErrorSeverity($severity); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @return string |
| 52 | * converts the error constant to a string |
| 53 | */ |
| 54 | public function getFriendlyType(): string |
| 55 | { |
| 56 | return ErrorHandler::friendlyErrorType($this->getSeverity()); |
| 57 | } |
| 58 | } |