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

InvalidEntityException::getErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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
ccs 0
cts 2
cp 0
crap 2
rs 10
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