Passed
Push — master ( c81bf2...c3afe7 )
by Aleksei
09:08 queued 01:17
created

ArgumentResolvingException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createWithParam() 0 3 1
A __construct() 0 7 1
A createStatic() 0 6 2
A getParameter() 0 3 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
final class ArgumentResolvingException 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\Re...umentResolvingException.
Loading history...
12
13 10
    private function __construct(
14
        private readonly \ReflectionFunctionAbstract $reflection,
15
        private readonly string $parameter,
16
        ?string $message = null,
17
    ) {
18 10
        $message ??= "Unable to resolve required argument `{$parameter}` when resolving `%s` %s.";
19 10
        parent::__construct($this->renderFunctionAndParameter($reflection, $message));
20
    }
21
22 10
    public static function createWithParam(\ReflectionFunctionAbstract $reflection, string $parameter): self
23
    {
24 10
        return new self($reflection, $parameter);
25
    }
26
27 2
    public function getParameter(): string
28
    {
29 2
        return $this->parameter;
30
    }
31
32 5
    protected static function createStatic(string $message, ?\Throwable $previous): static
33
    {
34 5
        $previous instanceof self or throw new \InvalidArgumentException(
35 5
            \sprintf('Previous exception must be an instance of %s', self::class),
36 5
        );
37 5
        return new self($previous->reflection, $previous->parameter);
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