EntityInvalidException::getErrors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Audiens\AdForm\Exception;
4
5
use Throwable;
6
7
/**
8
 * Exception thrown if an entity storage operation fails
9
 */
10
class EntityInvalidException extends SeverityAwareException
11
{
12
    protected const MESSAGE = 'Entity failed validation: %s';
13
14
    /**
15
     * @var mixed
16
     */
17
    protected $errors;
18
19
    public function __construct(
20
        string $message = '',
21
        int $code = 0,
22
        array $errors = [],
23
        ?Throwable $previous = null,
24
        int $severityLevel = self::SEVERITY_INFO
25
    ) {
26
        parent::__construct($message, $code, $previous, $severityLevel);
27
28
        $this->errors = $errors;
29
    }
30
31
    public static function invalid(string $message, int $code, array $errors): self
32
    {
33
        return new self (
34
            sprintf(self::MESSAGE, $message),
35
            $code,
36
            $errors,
37
            null,
38
            SeverityAwareException::SEVERITY_CRITICAL
39
        );
40
    }
41
42
    public function getErrors(): array
43
    {
44
        return $this->errors;
45
    }
46
}
47