2017-08-18 22:57:27 +02:00
|
|
|
<?php declare(strict_types=1);
|
2016-10-09 13:15:24 +02:00
|
|
|
|
|
|
|
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 $errors = [];
|
|
|
|
|
|
|
|
public function handleError(Error $error) {
|
|
|
|
$this->errors[] = $error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get collected errors.
|
|
|
|
*
|
|
|
|
* @return Error[]
|
|
|
|
*/
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getErrors() : array {
|
2016-10-09 13:15:24 +02:00
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether there are any errors.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-04-28 21:40:59 +02:00
|
|
|
public function hasErrors() : bool {
|
2016-10-09 13:15:24 +02:00
|
|
|
return !empty($this->errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset/clear collected errors.
|
|
|
|
*/
|
|
|
|
public function clearErrors() {
|
|
|
|
$this->errors = [];
|
|
|
|
}
|
|
|
|
}
|