Passed
Pull Request — master (#1222)
by Aleksei
13:25
created

ValidationException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getParameter() 0 3 1
A createStatic() 0 6 2
A createWithParam() 0 3 1
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Exception\Resolver;
6
7
use Spiral\Core\Exception\Traits\ClosureRendererTrait;
8
9
abstract class ValidationException extends ResolvingException
10
{
11
    use ClosureRendererTrait;
0 ignored issues
show
Bug introduced by
The trait Spiral\Core\Exception\Traits\ClosureRendererTrait requires the property $class which is not provided by Spiral\Core\Exception\Resolver\ValidationException.
Loading history...
12
13 24
    final private function __construct(
14
        protected readonly \ReflectionFunctionAbstract $reflection,
15
        protected readonly string $parameter,
16
        ?string $message = null,
17
    ) {
18 24
        $message ??= $this->getValidationMessage($reflection, $parameter);
19 24
        parent::__construct($this->renderFunctionAndParameter($reflection, $message));
20
    }
21
22 24
    public static function createWithParam(\ReflectionFunctionAbstract $reflection, string $parameter): static
23
    {
24 24
        return new static($reflection, $parameter);
25
    }
26
27 10
    public function getParameter(): string
28
    {
29 10
        return $this->parameter;
30
    }
31
32 7
    protected static function createStatic(string $message, ?\Throwable $previous): static
33
    {
34 7
        $previous instanceof self or throw new \InvalidArgumentException(
35 7
            \sprintf('Previous exception must be an instance of %s.', self::class),
36 7
        );
37 7
        return new static($previous->reflection, $previous->parameter, $message);
0 ignored issues
show
Bug introduced by
Accessing reflection on the interface Throwable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing parameter on the interface Throwable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
38
    }
39
40
    abstract protected function getValidationMessage(
41
        \ReflectionFunctionAbstract $reflection,
42
        string $parameter,
43
    ): string;
44
}
45