| Conditions | 2 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 102 | public function register(): void |
||
| 103 | { |
||
| 104 | |||
| 105 | // User authentication |
||
| 106 | $this->app->bind(UserAuthenticationInterface::class, UserAuthentication::class); |
||
| 107 | |||
| 108 | // Configuration |
||
| 109 | $this->app->bind(Configuration::class, function (ContainerInterface $app) { |
||
| 110 | return new Configuration($app->get(Config::class)->get('oauth2', [])); |
||
| 111 | }); |
||
| 112 | |||
| 113 | // Grants |
||
| 114 | $this->app->bind(AuthorizationGrant::class); |
||
| 115 | $this->app->bind(ClientCredentialsGrant::class); |
||
| 116 | $this->app->bind(RefreshTokenGrant::class); |
||
| 117 | $this->app->bind(PasswordGrant::class); |
||
| 118 | |||
| 119 | // Repositories |
||
| 120 | $this->app->bind(AccessTokenRepositoryInterface::class, AccessTokenRepository::class); |
||
| 121 | $this->app->bind(ScopeRepositoryInterface::class, ScopeRepository::class); |
||
| 122 | $this->app->bind(ClientRepositoryInterface::class, ClientRepository::class); |
||
| 123 | $this->app->bind(RefreshTokenRepositoryInterface::class, RefreshTokenRepository::class); |
||
| 124 | $this->app->bind(AuthorizationCodeRepositoryInterface::class, AuthorizationCodeRepository::class); |
||
| 125 | |||
| 126 | // Services |
||
| 127 | $this->app->bind(ScopeService::class); |
||
| 128 | $this->app->bind(AccessTokenService::class); |
||
| 129 | $this->app->bind(ClientService::class); |
||
| 130 | $this->app->bind(RefreshTokenService::class); |
||
| 131 | $this->app->bind(AuthorizationCodeService::class); |
||
| 132 | |||
| 133 | // Servers |
||
| 134 | $this->app->bind(ResourceServerInterface::class, ResourceServer::class); |
||
| 135 | $this->app->bind(AuthorizationServerInterface::class, function (ContainerInterface $app) { |
||
| 136 | /** @var Configuration $cfg */ |
||
| 137 | $cfg = $app->get(Configuration::class); |
||
| 138 | $grants = $cfg->getGrants(); |
||
| 139 | $serverGrants = []; |
||
| 140 | foreach ($grants as $grant) { |
||
| 141 | $serverGrants[] = $app->get($grant); |
||
| 142 | } |
||
| 143 | |||
| 144 | return new AuthorizationServer( |
||
| 145 | $app->get(ClientService::class), |
||
| 146 | $app->get(AccessTokenService::class), |
||
| 147 | $app->get(RefreshTokenService::class), |
||
| 148 | $app->get(LoggerInterface::class), |
||
| 149 | $serverGrants |
||
| 150 | ); |
||
| 151 | }); |
||
| 152 | |||
| 153 | // Middlewares |
||
| 154 | $this->app->bind(ResourceServerMiddleware::class); |
||
| 155 | $this->app->bind(AuthorizationRequestMiddleware::class); |
||
| 156 | $this->app->bind(TokenRequestMiddleware::class); |
||
| 157 | $this->app->bind(RevocationRequestMiddleware::class); |
||
| 158 | $this->app->bind(OauthResourceMiddleware::class); |
||
| 159 | |||
| 160 | // Handlers |
||
| 161 | $this->app->bind(AccessTokenRequestHandler::class); |
||
| 162 | $this->app->bind(AuthorizationRequestHandler::class); |
||
| 163 | $this->app->bind(TokenRevocationRequestHandler::class); |
||
| 164 | } |
||
| 178 |