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;
return $this;
}
public function hasErrors()
return !empty($this->errors);
public function getErrors()
return $this->errors;
public function mergeErrors(ErrorContainerInterface $errorContainer)
if ($errorContainer->hasErrors()) {
foreach ($errorContainer->getErrors() as $error) {
$this->addError($error);
public function getErrorsArray($inGraphQLStyle = true)
$errors = [];
foreach ($this->errors as $error) {
if ($inGraphQLStyle) {
if ($error instanceof DatableResolveException) {
$errors[] = array_merge(
['message' => $error->getMessage()],
$error->getData() ?: [],
$error->getCode() ? ['code' => $error->getCode()] : []
);
} else {
$errors[] = $error->getMessage();
return $errors;
public function clearErrors()
$this->errors = [];