Test Failed
Pull Request — master (#64)
by
unknown
04:17
created

MetadataRouteProvider::getAuthMiddleware()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 9
nc 6
nop 0
1
<?php
2
3
namespace AlgoWeb\PODataLaravel\Providers;
4
5
use Illuminate\Support\Facades\App;
6
use Illuminate\Support\Facades\Route;
7
use Illuminate\Support\ServiceProvider;
8
9
class MetadataRouteProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        self::setupRoute();
19
    }
20
21
    private static function setupRoute()
22
    {
23
        $auth_middleware = self::getAuthMiddleware();
24
25
        Route::any(
26
            'odata.svc/{section}',
27
            ['uses' => 'AlgoWeb\PODataLaravel\Controllers\ODataController@index', 'middleware' => $auth_middleware]
28
        )
29
            ->where(['section' => '.*']);
30
        Route::any(
31
            'odata.svc',
32
            ['uses' => 'AlgoWeb\PODataLaravel\Controllers\ODataController@index', 'middleware' => $auth_middleware]
33
        );
34
    }
35
36
    /**
37
     * Register the application services.
38
     *
39
     * @return void
40
     */
41
    public function register()
42
    {
43
        //
44
    }
45
46
    private static function getAuthMiddleware()
47
    {
48
        $auth_middleware = 'auth.basic';
49
50
        try {
51
            if (class_exists(\Illuminate\Contracts\Auth\Factory::class)) {
52
                $manager = App::make(\Illuminate\Contracts\Auth\Factory::class);
53
                if ($manager->guard('api')) {
54
                    $auth_middleware = 'auth:api';
55
                }
56
            }
57
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
58
59
        }
60
61
        return $auth_middleware;
62
    }
63
}
64