Files
apimacro/vendor/nikic/php-parser/lib/PhpParser/ErrorHandler/Collecting.php

44 lines
869 B
PHP
Raw Normal View History

2024-05-07 12:17:25 +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.
*/
2024-05-17 12:24:19 +00:00
class Collecting implements ErrorHandler {
2024-05-07 12:17:25 +02:00
/** @var Error[] Collected errors */
2024-05-17 12:24:19 +00:00
private array $errors = [];
2024-05-07 12:17:25 +02:00
2024-05-17 12:24:19 +00:00
public function handleError(Error $error): void {
2024-05-07 12:17:25 +02:00
$this->errors[] = $error;
}
/**
* Get collected errors.
*
* @return Error[]
*/
2024-05-17 12:24:19 +00:00
public function getErrors(): array {
2024-05-07 12:17:25 +02:00
return $this->errors;
}
/**
* Check whether there are any errors.
*/
2024-05-17 12:24:19 +00:00
public function hasErrors(): bool {
2024-05-07 12:17:25 +02:00
return !empty($this->errors);
}
/**
* Reset/clear collected errors.
*/
2024-05-17 12:24:19 +00:00
public function clearErrors(): void {
2024-05-07 12:17:25 +02:00
$this->errors = [];
}
}