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

InvalidEntityException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 10
c 3
b 1
f 0
dl 0
loc 26
rs 10
ccs 8
cts 10
cp 0.8
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrors() 0 3 1
A fromViolations() 0 13 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