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

ExceptionResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 23
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 10 4
A __construct() 0 3 1
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