Passed
Push — master ( 29521a...b34be3 )
by Alexander
24:53 queued 23:31
created

RequestValidationException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFirstErrors() 0 3 1
A getErrors() 0 3 1
A __construct() 0 4 1
A getFirstError() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\RequestModel;
6
7
use RuntimeException;
8
9
final class RequestValidationException extends RuntimeException
10
{
11
    private const MESSAGE = 'Request model validation error';
12
    private array $errors;
13
14 4
    public function __construct(array $errors)
15
    {
16 4
        $this->errors = $errors;
17 4
        parent::__construct(self::MESSAGE);
18 4
    }
19
20 1
    public function getErrors(): array
21
    {
22 1
        return $this->errors;
23
    }
24
25 2
    public function getFirstErrors(): ?array
26
    {
27 2
        return reset($this->errors);
28
    }
29
30 1
    public function getFirstError(): ?string
31
    {
32 1
        $errors = $this->getFirstErrors();
33
34 1
        return reset($errors);
0 ignored issues
show
Bug introduced by
It seems like $errors can also be of type null; however, parameter $array of reset() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        return reset(/** @scrutinizer ignore-type */ $errors);
Loading history...
35
    }
36
}
37