Passed
Pull Request — master (#19)
by Samuel
02:03
created

AddCustomProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 39
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 3
A terminate() 0 5 1
1
<?php
2
3
namespace SMartins\PassportMultiauth\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class AddCustomProvider
9
{
10
    /**
11
     * The default provder of api guard.
12
     *
13
     * @var string
14
     */
15
    protected $defaultApiProvider;
16
17
    /**
18
     * Handle an incoming request. Set the `provider` from `api` guard using a
19
     * parameter `provider` coming from request. The provider on `apì` guard
20
     * is used by Laravel Passport to get the correct model on access token
21
     * creation.
22
     *
23
     * @param  \Illuminate\Http\Request  $request
24
     * @param  \Closure  $next
25
     * @return mixed
26
     */
27 1
    public function handle(Request $request, Closure $next)
28
    {
29 1
        $this->defaultApiProvider = config('auth.guards.api.provider');
30
31 1
        $params = $request->all();
32 1
        if (array_key_exists('provider', $params)) {
33 1
            if (! is_null($params['provider'])) {
34 1
                config(['auth.guards.api.provider' => $params['provider']]);
35
            }
36
        }
37
38 1
        return $next($request);
39
    }
40
41
    public function terminate($request, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        // Reset config provider to default after complete request.
44
        config(['auth.guards.api.provider' => $this->defaultApiProvider]);
45
    }
46
}
47