Passed
Pull Request — master (#1)
by
unknown
14:51
created

RequestValidationException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
    public function __construct(array $errors)
15
    {
16
        $this->errors = $errors;
17
        parent::__construct(self::MESSAGE);
18
    }
19
20
    public function getErrors(): array
21
    {
22
        return $this->errors;
23
    }
24
25
    public function getFirstErrors(): ?array
26
    {
27
        return reset($this->errors);
28
    }
29
30
    public function getFirstError(): ?string
31
    {
32
        $errors = $this->getFirstErrors();
33
34
        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