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

AddCustomProvider::terminate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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