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

ArgumentResolvingException::createStatic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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