wol-soft/php-json-schema-model-generator-production

View on GitHub
src/Exception/ErrorRegistryException.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types = 1);

namespace PHPModelGenerator\Exception;

/**
 * Class ErrorRegistryException
 *
 * @package PHPModelGeneratorException
 */
class ErrorRegistryException extends JSONModelValidationException implements ErrorRegistryExceptionInterface
{
    protected $errors = [];

    /**
     * @inheritdoc
     */
    public function addError(ValidationException $exception): ErrorRegistryExceptionInterface
    {
        $this->errors[] = $exception;

        $this->message = join(
            "\n",
            array_map(
                function (ValidationException $e): string {
                    return $e->getMessage();
                },
                $this->errors
            )
        );

        return $this;
    }

    /**
     * @inheritdoc
     */
    public function getErrors(): array
    {
        return $this->errors;
    }
}