AuthServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 3
eloc 10
c 3
b 0
f 2
nc 4
nop 0
dl 0
loc 15
rs 9.9332
1
<?php
2
3
namespace FaithGen\SDK\Providers;
4
5
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
6
use Illuminate\Support\Facades\Auth;
7
8
final class AuthServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * The policy mappings for the application.
12
     *
13
     * @var array
14
     */
15
    protected $policies = [];
16
17
    /**
18
     * Register services.
19
     *
20
     * @return void
21
     */
22
    public function register()
23
    {
24
        //
25
    }
26
27
    /**
28
     * Bootstrap services.
29
     *
30
     * @return void
31
     */
32
    public function boot()
33
    {
34
        if (request()->headers->has('x-user-key')) {
35
            $user_id = request()->headers->get('x-user-key');
36
            Auth::guard('web')->loginUsingId($user_id);
37
        }
38
39
        if (! config('faithgen-sdk.source')) {
40
            Auth::viaRequest('api-key', function ($request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
            Auth::viaRequest('api-key', function (/** @scrutinizer ignore-unused */ $request) {

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

Loading history...
41
                $api_key = request()->headers->get('x-api-key');
42
                $class = config('auth.providers.ministries.model');
43
44
                return $class::whereHas('apiKey', function ($apiKey) use ($api_key) {
45
                    return $apiKey->where('api_key', $api_key);
46
                })->first();
47
            });
48
        }
49
    }
50
}
51