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

MetadataRouteProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A setupRoute() 0 14 1
A register() 0 4 1
A getAuthMiddleware() 0 17 4
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