| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Dependencies\PhpParser\ErrorHandler; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Dependencies\PhpParser\Error; |
| 6 |
use WPDeveloper\BetterDocs\Dependencies\PhpParser\ErrorHandler; |
| 7 |
|
| 8 |
/** |
| 9 |
* Error handler that collects all errors into an array. |
| 10 |
* |
| 11 |
* This allows graceful handling of errors. |
| 12 |
*/ |
| 13 |
class Collecting implements ErrorHandler |
| 14 |
{ |
| 15 |
/** @var Error[] Collected errors */ |
| 16 |
private $errors = []; |
| 17 |
|
| 18 |
public function handleError(Error $error) { |
| 19 |
$this->errors[] = $error; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Get collected errors. |
| 24 |
* |
| 25 |
* @return Error[] |
| 26 |
*/ |
| 27 |
public function getErrors() { |
| 28 |
return $this->errors; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Check whether there are any errors. |
| 33 |
* |
| 34 |
* @return bool |
| 35 |
*/ |
| 36 |
public function hasErrors() { |
| 37 |
return !empty($this->errors); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Reset/clear collected errors. |
| 42 |
*/ |
| 43 |
public function clearErrors() { |
| 44 |
$this->errors = []; |
| 45 |
} |
| 46 |
} |