Conditions | 12 |
Paths | 34 |
Total Lines | 114 |
Code Lines | 83 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
51 | public function loadConfiguration() |
||
52 | { |
||
53 | $builder = $this->getContainerBuilder(); |
||
54 | $config = $this->validateConfig($this->defaults); |
||
55 | |||
56 | // Table mapping & Login redirection |
||
57 | $builder->addDefinition($this->prefix('tablePrefixSubscriber')) |
||
58 | ->setClass(TablePrefixSubscriber::class) |
||
59 | ->addTag(EventsExtension::TAG_SUBSCRIBER); |
||
60 | $builder->addDefinition($this->prefix('loginSubscriber')) |
||
61 | ->setClass(LoginSubscriber::class) |
||
62 | ->addTag(EventsExtension::TAG_SUBSCRIBER); |
||
63 | |||
64 | // Common repositories |
||
65 | $builder->addDefinition($this->prefix('repository.accessToken')) |
||
66 | ->setClass(AccessTokenRepository::class); |
||
67 | $builder->addDefinition($this->prefix('repository.authCode')) |
||
68 | ->setClass(AuthCodeRepository::class); |
||
69 | $builder->addDefinition($this->prefix('repository.client')) |
||
70 | ->setClass(ClientRepository::class); |
||
71 | $builder->addDefinition($this->prefix('repository.refreshToken')) |
||
72 | ->setClass(RefreshTokenRepository::class); |
||
73 | $builder->addDefinition($this->prefix('repository.scope')) |
||
74 | ->setClass(ScopeRepository::class); |
||
75 | $builder->addDefinition($this->prefix('repository.user')) |
||
76 | ->setClass(UserRepository::class); |
||
77 | |||
78 | // Encryption keys |
||
79 | Validators::assertField($config, 'publicKey', 'string'); |
||
80 | Validators::assertField($config, 'privateKey', 'string|array'); |
||
81 | if (is_array($config['privateKey'])) { |
||
82 | Validators::assertField($config['privateKey'], 'keyPath', 'string'); |
||
83 | Validators::assertField($config['privateKey'], 'passPhrase', 'string'); |
||
84 | $privateKey = new Statement(CryptKey::class, [$config['privateKey']['keyPath'], $config['privateKey']['passPhrase']]); |
||
85 | |||
86 | } else { |
||
87 | $privateKey = $config['privateKey']; |
||
88 | } |
||
89 | |||
90 | // Authorization & resource server |
||
91 | $authorizationServer = $builder->addDefinition($this->prefix('authorizationServer')) |
||
92 | ->setClass(AuthorizationServer::class, [ |
||
93 | 'privateKey' => $privateKey, |
||
94 | 'publicKey' => $config['publicKey'], |
||
95 | ]); |
||
96 | $builder->addDefinition($this->prefix('resourceServer')) |
||
97 | ->setClass(ResourceServer::class, [ |
||
98 | 'publicKey' => $config['publicKey'], |
||
99 | ]); |
||
100 | |||
101 | // Grants |
||
102 | Validators::assertField($config, 'grants', 'array'); |
||
103 | foreach ($config['grants'] as $grant => $options) { |
||
104 | Validators::assert($options, 'boolean|array'); |
||
105 | if ($options === false) { |
||
106 | continue; |
||
107 | |||
108 | } else { |
||
109 | $options = (array) $options; |
||
110 | } |
||
111 | |||
112 | $definition = $builder->addDefinition($this->prefix('grant.' . $grant)); |
||
113 | |||
114 | switch ($grant) { |
||
115 | case 'authCode': |
||
116 | if (!array_key_exists('authCodeTtl', $options)) { |
||
117 | $options['authCodeTtl'] = 'PT10M'; |
||
118 | } |
||
119 | $definition->setClass(AuthCodeGrant::class, ['authCodeTTL' => $this->createDateIntervalStatement($options['authCodeTtl'])]); |
||
120 | break; |
||
121 | case 'clientCredentials': |
||
122 | $definition->setClass(ClientCredentialsGrant::class); |
||
123 | break; |
||
124 | case 'implicit': |
||
125 | if (!array_key_exists('accessTokenTtl', $options)) { |
||
126 | $options['accessTokenTtl'] = 'PT10M'; |
||
127 | } |
||
128 | $definition->setClass(ImplicitGrant::class, ['accessTokenTTL' => $this->createDateIntervalStatement($options['accessTokenTtl'])]); |
||
129 | break; |
||
130 | case 'password': |
||
131 | $definition->setClass(PasswordGrant::class); |
||
132 | break; |
||
133 | case 'refreshToken': |
||
134 | $definition->setClass(RefreshTokenGrant::class); |
||
135 | break; |
||
136 | default: |
||
137 | throw new \InvalidArgumentException(sprintf('Unknown grant %s', $grant)); |
||
138 | } |
||
139 | |||
140 | $args = [$this->prefix('@grant.' . $grant)]; |
||
141 | if (array_key_exists('ttl', $options)) { |
||
142 | $args[] = $this->createDateIntervalStatement($options['ttl']); |
||
143 | } |
||
144 | $authorizationServer->addSetup('enableGrantType', $args); |
||
145 | } |
||
146 | |||
147 | // Presenter, Control factory, Serializer |
||
148 | $builder->addDefinition($this->prefix('presenter')) |
||
149 | ->setClass(OAuth2Presenter::class); |
||
150 | $builder->addDefinition($this->prefix('approveControlFactory')) |
||
151 | ->setClass(ApproveControlFactory::class); |
||
152 | $builder->addDefinition($this->prefix('serializer')) |
||
153 | ->setClass(IAuthorizationRequestSerializer::class) |
||
154 | ->setFactory(AuthorizationRequestSerializer::class); |
||
155 | |||
156 | // Redirect config |
||
157 | Validators::assertField($config, 'approveDestination', 'string|null'); |
||
158 | Validators::assertField($config, 'loginDestination', 'string|null'); |
||
159 | $builder->addDefinition($this->prefix('redirectConfig')) |
||
160 | ->setClass(RedirectConfig::class, [ |
||
161 | 'approveDestination' => $config['approveDestination'], |
||
162 | 'loginDestination' => $config['loginDestination'], |
||
163 | ]); |
||
164 | } |
||
165 | |||
196 |