for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Date: 01.12.15
*
* @author Portey Vasil <[email protected]>
*/
namespace Youshido\GraphQL\Validator\ErrorContainer;
use Youshido\GraphQL\Validator\Exception\DatableResolveException;
trait ErrorContainerTrait
{
/** @var \Exception[] */
protected $errors = [];
public function addError(\Exception $exception)
$this->errors[] = $exception;
}
public function hasErrors()
return !empty($this->errors);
public function getErrors()
return $this->errors;
public function getErrorsArray($asObject = true)
$errors = [];
foreach ($this->errors as $error) {
if ($asObject) {
if (is_object($error)) {
if ($error instanceof DatableResolveException) {
$errors[] = array_merge(
['message' => $error->getMessage()],
$error->getData() ?: [],
$error->getCode() ? ['code' => $error->getCode()] : []
);
} else {
$errors[] = ['message' => $error];
$errors[] = $error->getMessage();
$errors[] = $error;
return $errors;
public function clearErrors()
$this->errors = [];
return $this;