InvalidEntityException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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