1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-12 17:37:21 +01:00
PHP-Parser/lib/PhpParser/ErrorHandler/Collecting.php

47 lines
880 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 $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 {
return $this->errors;
}
/**
* Check whether there are any errors.
*
* @return bool
*/
2017-04-28 21:40:59 +02:00
public function hasErrors() : bool {
return !empty($this->errors);
}
/**
* Reset/clear collected errors.
*/
public function clearErrors() {
$this->errors = [];
}
2018-01-10 18:04:06 +01:00
}