Passed
Push — master ( d8182e...614f25 )
by Paweł
03:01
created

InvalidEntityException::fromViolations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 10
ccs 8
cts 8
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
    public function getErrors(): array
22
    {
23
        return $this->errors;
24
    }
25
26 1
    public static function fromViolations(EntityViolation ...$violations): self
27
    {
28 1
        $message = array_map(
29 1
            static function (EntityViolation $violation): string {
30 1
                return "{$violation->getProperty()}: {$violation->getMessage()}";
31 1
            },
32
            $violations
33
        );
34
35 1
        $self = new self(implode('; ', $message));
36 1
        $self->errors = $violations;
37
38 1
        return $self;
39
    }
40
}
41