44 lines
869 B
PHP
Raw Normal View History

2017-08-18 22:57:27 +02:00
<?php declare(strict_types=1);
namespace PhpParser\ErrorHandler;
use PhpParser\Error;
use PhpParser\ErrorHandler;
/**
* Error handler that collects all errors into an array.
*
* This allows graceful handling of errors.
*/
class Collecting implements ErrorHandler {
/** @var Error[] Collected errors */
private array $errors = [];
2022-09-11 17:51:59 +02:00
public function handleError(Error $error): void {
$this->errors[] = $error;
}
/**
* Get collected errors.
*
* @return Error[]
*/
public function getErrors(): array {
return $this->errors;
}
/**
* Check whether there are any errors.
*/
public function hasErrors(): bool {
return !empty($this->errors);
}
/**
* Reset/clear collected errors.
*/
2022-09-11 17:51:59 +02:00
public function clearErrors(): void {
$this->errors = [];
}
2018-01-10 15:04:06 -02:00
}