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

RequestValidationException::getFirstError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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