Test Failed
Push — master ( fc5cfa...18d5e6 )
by Alex
03:42
created

MetadataRouteProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A setupRoute() 0 11 1
A register() 0 3 1
A getAuthMiddleware() 0 16 4
A isAuthDisable() 0 4 1
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
        $this->setupRoute();
19
    }
20
21
    private function setupRoute()
22
    {
23
        $authMiddleware = $this->getAuthMiddleware();
24
        $controllerMethod = 'AlgoWeb\PODataLaravel\Controllers\ODataController@index';
25
26
        Route::get('odata.svc/$metadata', ['uses' => $controllerMethod, 'middleware' => null]);
27
28
        Route::any('odata.svc/{section}', ['uses' => $controllerMethod, 'middleware' => $authMiddleware])
29
            ->where(['section' => '.*']);
30
        Route::any('odata.svc', ['uses' => $controllerMethod, 'middleware' => null]);
31
    }
32
33
    /**
34
     * Register the application services.
35
     *
36
     * @return void
37
     */
38
    public function register()
39
    {
40
    }
41
42
    private function getAuthMiddleware()
43
    {
44
        $disable = $this->isAuthDisable();
45
        if ($disable) {
46
            return null;
47
        }
48
49
        $authMiddleware = 'auth.basic';
50
51
        if (interface_exists(\Illuminate\Contracts\Auth\Factory::class)) {
52
            $manager = App::make(\Illuminate\Contracts\Auth\Factory::class);
53
            $authMiddleware = $manager->guard('api') ? 'auth:api' : $authMiddleware;
54
        }
55
56
        return $authMiddleware;
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    protected function isAuthDisable()
63
    {
64
        return true === config('APP_DISABLE_AUTH', null);
65
    }
66
}
67