Passed
Push — master ( e84e4b...dd6318 )
by Smoren
02:33
created

FormValidationError::getViolatedRestrictions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Exceptions;
6
7
final class FormValidationError extends \DomainException
8
{
9
    /**
10
     * @var class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
11
     */
12
    protected string $formClass;
13
    /**
14
     * @var array<string, ValidationError>
15
     */
16
    protected array $attributeErrorMap;
17
18
    /**
19
     * @param class-string $formClass
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
20
     * @param array<string, ValidationError> $attributeErrorMap
21
     */
22
    public function __construct(string $formClass, array $attributeErrorMap)
23
    {
24
        parent::__construct('Validation error');
25
        $this->formClass = $formClass;
26
        $this->attributeErrorMap = $attributeErrorMap;
27
    }
28
29
    /**
30
     * @return class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
31
     */
32
    public function getFormClass(): string
33
    {
34
        return $this->formClass;
35
    }
36
37
    /**
38
     * @return array<string, array<array{string, array<string, mixed>}>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, array<arra...array<string, mixed>}>> at position 8 could not be parsed: Expected ':' at position 8, but found 'string'.
Loading history...
39
     */
40
    public function getViolatedRestrictions(): array
41
    {
42
        $result = [];
43
        foreach ($this->attributeErrorMap as $attrName => $error) {
44
            $result[$attrName] = $error->getViolatedRestrictions();
45
        }
46
        return $result;
47
    }
48
}
49