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

GuardsResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 14 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 Symfony\Component\HttpFoundation\File\Exception\UnexpectedTypeException;
15
16
class GuardsResolver extends Resolver
17
{
18
    protected $guard;
19
20
    /**
21
     * GuardsResolver constructor.
22
     * @param $guard
23
     */
24 2
    public function __construct($guard)
25
    {
26 2
        $this->guard = $guard;
27 2
    }
28
29 2
    public function resolve()
30
    {
31 2
        $guards = [];
32 2
        if (!is_array($this->guard)) {
33 2
            $guards[] = $this->guard;
34
        }
35
        else
36
        $guards = $this->guard;
37
38 2
        foreach ($guards as $guard) {
39 2
            if (!($guard instanceof GuardContract))
40
                throw new UnexpectedTypeException($guard, GuardContract::class);
41
        }
42 2
        return $guards;
43
    }
44
45
46
}
47