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 |
||
| 28 | class FluentStorageServiceProvider extends ServiceProvider |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * Bootstrap the application events. |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | 108 | public function boot() |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Register the service provider. |
||
| 42 | * |
||
| 43 | * @return void |
||
| 44 | */ |
||
| 45 | 108 | public function register() |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Bind the storage implementations to the IoC container. |
||
| 53 | * |
||
| 54 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
|
|
|||
| 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) { |
|
| 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) { |
|
| 70 | $storage = new FluentAuthCode($provider->app['db']); |
||
| 71 | $storage->setConnectionName($provider->getConnectionName()); |
||
| 72 | |||
| 73 | return $storage; |
||
| 74 | 108 | }); |
|
| 75 | |||
| 76 | $app->singleton(FluentClient::class, function ($app) use ($provider) { |
||
| 77 | $limitClientsToGrants = $app['config']->get('oauth2.limit_clients_to_grants'); |
||
| 78 | $storage = new FluentClient($provider->app['db'], $limitClientsToGrants); |
||
| 79 | $storage->setConnectionName($provider->getConnectionName()); |
||
| 80 | |||
| 81 | return $storage; |
||
| 82 | 108 | }); |
|
| 83 | |||
| 84 | View Code Duplication | $app->singleton(FluentRefreshToken::class, function () use ($provider) { |
|
| 85 | $storage = new FluentRefreshToken($provider->app['db']); |
||
| 86 | $storage->setConnectionName($provider->getConnectionName()); |
||
| 87 | |||
| 88 | return $storage; |
||
| 89 | 108 | }); |
|
| 90 | |||
| 91 | $app->singleton(FluentScope::class, function ($app) use ($provider) { |
||
| 92 | $limitClientsToScopes = $app['config']->get('oauth2.limit_clients_to_scopes'); |
||
| 93 | $limitScopesToGrants = $app['config']->get('oauth2.limit_scopes_to_grants'); |
||
| 94 | $storage = new FluentScope($provider->app['db'], $limitClientsToScopes, $limitScopesToGrants); |
||
| 95 | $storage->setConnectionName($provider->getConnectionName()); |
||
| 96 | |||
| 97 | return $storage; |
||
| 98 | 108 | }); |
|
| 99 | |||
| 100 | 108 | View Code Duplication | $app->singleton(FluentSession::class, function () use ($provider) { |
| 101 | $storage = new FluentSession($provider->app['db']); |
||
| 102 | $storage->setConnectionName($provider->getConnectionName()); |
||
| 103 | |||
| 104 | return $storage; |
||
| 105 | 108 | }); |
|
| 106 | 108 | } |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Bind the interfaces to their implementations. |
||
| 110 | * |
||
| 111 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
| 112 | * |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | 108 | public function registerInterfaceBindings(Application $app) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | public function getConnectionName() |
||
| 132 | } |
||
| 133 |
This check looks for
@paramannotations 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.