Passed
Push — master ( 624a9a...4c85b9 )
by Arthur
36:47
created

ExceptionResolver::resolve()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.5923

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 3
nop 0
dl 0
loc 10
ccs 4
cts 6
cp 0.6667
crap 4.5923
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 24.03.19
6
 * Time: 19:41
7
 */
8
9
namespace Foundation\Guard\Resolvers;
10
11
12
use Foundation\Guard\Abstracts\Resolver;
13
use Foundation\Guard\Contracts\GuardContract;
14
use Foundation\Guard\Exceptions\CouldNotResolveStringException;
15
use Symfony\Component\HttpFoundation\File\Exception\UnexpectedTypeException;
16
17
class ExceptionResolver extends Resolver
18
{
19
    protected $exception;
20
21
    /**
22
     * GuardsResolver constructor.
23
     * @param $exception
24
     */
25 1
    public function __construct($exception)
26
    {
27 1
        $this->exception = $exception;
28 1
    }
29
30 1
    public function resolve()
31
    {
32 1
        if (is_string($this->exception) || !($this->exception instanceof \Throwable)) {
33
            try {
34 1
                $exception = new $this->exception;
35
            } catch (\Exception $e) {
36
                throw new CouldNotResolveStringException("Could not resolve the string to an exception. It probably requires additional arguments. try to pass it as an object to the dispatcher");
37
            }
38
        }
39 1
        return $exception;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $exception does not seem to be defined for all execution paths leading up to this point.
Loading history...
40
    }
41
42
43
}
44