Completed
Pull Request — master (#779)
by
unknown
61:21 queued 60:00
created

FluentStorageServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 37.74 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 50%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 8
dl 40
loc 106
ccs 24
cts 48
cp 0.5
rs 10
c 3
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 5 1
A registerStorageBindings() 40 50 1
A registerInterfaceBindings() 0 9 1
A getConnectionName() 0 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of OAuth 2.0 Laravel.
5
 *
6
 * (c) Luca Degasperi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LucaDegasperi\OAuth2Server\Storage;
13
14
use Illuminate\Contracts\Container\Container as Application;
15
use Illuminate\Support\ServiceProvider;
16
use League\OAuth2\Server\Storage\AccessTokenInterface;
17
use League\OAuth2\Server\Storage\AuthCodeInterface;
18
use League\OAuth2\Server\Storage\ClientInterface;
19
use League\OAuth2\Server\Storage\RefreshTokenInterface;
20
use League\OAuth2\Server\Storage\ScopeInterface;
21
use League\OAuth2\Server\Storage\SessionInterface;
22
23
/**
24
 * This is the fluent storage service provider class.
25
 *
26
 * @author Luca Degasperi <[email protected]>
27
 */
28
class FluentStorageServiceProvider extends ServiceProvider
29
{
30
    /**
31
     * Bootstrap the application events.
32
     *
33
     * @return void
34
     */
35 108
    public function boot()
36
    {
37
        //
38 108
    }
39
40
    /**
41
     * Register the service provider.
42
     *
43
     * @return void
44
     */
45 108
    public function register()
46
    {
47 108
        $this->registerStorageBindings($this->app);
48 108
        $this->registerInterfaceBindings($this->app);
49 108
    }
50
51
    /**
52
     * Bind the storage implementations to the IoC container.
53
     *
54
     * @param \Illuminate\Contracts\Foundation\Application $app
0 ignored issues
show
Documentation introduced by
Should the type for parameter $app not be Application?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
55
     *
56
     * @return void
57
     */
58 108
    public function registerStorageBindings(Application $app)
59
    {
60 108
        $provider = $this;
61
62 View Code Duplication
        $app->singleton(FluentAccessToken::class, function () use ($provider) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
            $storage = new FluentAccessToken($provider->app['db']);
64
            $storage->setConnectionName($provider->getConnectionName());
65
66
            return $storage;
67 108
        });
68
69 View Code Duplication
        $app->singleton(FluentAuthCode::class, function () use ($provider) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
            $storage = new FluentAuthCode($provider->app['db']);
71
            $storage->setConnectionName($provider->getConnectionName());
72
73
            return $storage;
74 108
        });
75
76 View Code Duplication
        $app->singleton(FluentClient::class, function ($app) use ($provider) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
            $limitClientsToGrants = $app['config']->get('oauth2.limit_clients_to_grants');
78
            $limitRedirectUri = $app['config']->get('oauth2.limit_clients_to_predefined_url');
79
            $storage = new FluentClient($provider->app['db'], $limitClientsToGrants, $limitRedirectUri);
80
            $storage->setConnectionName($provider->getConnectionName());
81
82
            return $storage;
83 108
        });
84
85 View Code Duplication
        $app->singleton(FluentRefreshToken::class, function () use ($provider) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
            $storage = new FluentRefreshToken($provider->app['db']);
87
            $storage->setConnectionName($provider->getConnectionName());
88
89
            return $storage;
90 108
        });
91
92 View Code Duplication
        $app->singleton(FluentScope::class, function ($app) use ($provider) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
            $limitClientsToScopes = $app['config']->get('oauth2.limit_clients_to_scopes');
94
            $limitScopesToGrants = $app['config']->get('oauth2.limit_scopes_to_grants');
95
            $storage = new FluentScope($provider->app['db'], $limitClientsToScopes, $limitScopesToGrants);
96
            $storage->setConnectionName($provider->getConnectionName());
97
98
            return $storage;
99 108
        });
100
101 108 View Code Duplication
        $app->singleton(FluentSession::class, function () use ($provider) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
            $storage = new FluentSession($provider->app['db']);
103
            $storage->setConnectionName($provider->getConnectionName());
104
105
            return $storage;
106 108
        });
107 108
    }
108
109
    /**
110
     * Bind the interfaces to their implementations.
111
     *
112
     * @param \Illuminate\Contracts\Foundation\Application $app
0 ignored issues
show
Documentation introduced by
Should the type for parameter $app not be Application?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
113
     *
114
     * @return void
115
     */
116 108
    public function registerInterfaceBindings(Application $app)
117
    {
118 108
        $app->bind(ClientInterface::class, FluentClient::class);
119 108
        $app->bind(ScopeInterface::class, FluentScope::class);
120 108
        $app->bind(SessionInterface::class, FluentSession::class);
121 108
        $app->bind(AuthCodeInterface::class, FluentAuthCode::class);
122 108
        $app->bind(AccessTokenInterface::class, FluentAccessToken::class);
123 108
        $app->bind(RefreshTokenInterface::class, FluentRefreshToken::class);
124 108
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getConnectionName()
130
    {
131
        return ($this->app['config']->get('oauth2.database') !== 'default') ? $this->app['config']->get('oauth2.database') : null;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
132
    }
133
}
134