Test Failed
Pull Request — master (#64)
by
unknown
06:49 queued 02:17
created

MetadataRouteProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 0
cbo 3
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 4 1
A setupRoute() 0 14 1
A getAuthMiddleware() 0 13 3
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
        if (class_exists(\Illuminate\Contracts\Auth\Factory::class)) {
51
            $manager = App::make(\Illuminate\Contracts\Auth\Factory::class);
52
            if ($manager->guard('api')) {
53
                $auth_middleware = 'auth:api';
54
            }
55
        }
56
57
        return $auth_middleware;
58
    }
59
}
60