InvalidEntityException::getErrors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 3
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2020.
4
 * @author Paweł Antosiak <[email protected]>
5
 */
6
7
declare(strict_types=1);
8
9
namespace Gorynych\Resource\Exception;
10
11
use Gorynych\Resource\Dto\EntityViolation;
12
13
class InvalidEntityException extends \LogicException
14
{
15
    /** @var EntityViolation[]  */
16
    private array $errors;
17
18
    /**
19
     * @return EntityViolation[]
20
     */
21 1
    public function getErrors(): array
22
    {
23 1
        return $this->errors;
24
    }
25
26 2
    public static function fromViolations(EntityViolation ...$violations): self
27
    {
28 2
        $message = array_map(
29 2
            static function (EntityViolation $violation): string {
30 2
                return "{$violation->getProperty()}: {$violation->getMessage()}";
31 2
            },
32
            $violations
33
        );
34
35 2
        $self = new self(implode('; ', $message));
36 2
        $self->errors = $violations;
37
38 2
        return $self;
39
    }
40
}
41