EntityInvalidException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 12
c 1
b 0
f 1
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A invalid() 0 8 1
A __construct() 0 10 1
A getErrors() 0 3 1
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