Conditions | 11 |
Paths | 1 |
Total Lines | 140 |
Code Lines | 116 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
123 | private function jwtNode(string $name): ArrayNodeDefinition |
||
124 | { |
||
125 | return (new ArrayNodeDefinition($name)) |
||
126 | ->beforeNormalization() |
||
127 | ->ifString() |
||
128 | ->then(function (string $config): array { |
||
129 | return ['signer' => $config]; |
||
130 | }) |
||
131 | ->end() |
||
132 | ->canBeEnabled() |
||
133 | ->children() |
||
134 | ->append($this->extractorsNode('extractors', [ |
||
135 | [ |
||
136 | 'type' => 'header', |
||
137 | 'name' => 'Authorization', |
||
138 | 'prefix' => 'Bearer', |
||
139 | ], |
||
140 | ])) |
||
141 | ->scalarNode('identity_claim') |
||
142 | ->cannotBeEmpty() |
||
143 | ->end() |
||
144 | ->arrayNode('builder') |
||
145 | ->addDefaultsIfNotSet() |
||
146 | ->children() |
||
147 | ->scalarNode('issuer') |
||
148 | ->cannotBeEmpty() |
||
149 | ->end() |
||
150 | ->scalarNode('audience') |
||
151 | ->cannotBeEmpty() |
||
152 | ->end() |
||
153 | ->integerNode('ttl') |
||
154 | ->defaultValue(3600) |
||
155 | ->end() |
||
156 | ->end() |
||
157 | ->end() |
||
158 | ->arrayNode('parser') |
||
159 | ->children() |
||
160 | ->arrayNode('issuers') |
||
161 | ->requiresAtLeastOneElement() |
||
162 | ->scalarPrototype() |
||
163 | ->isRequired() |
||
164 | ->end() |
||
165 | ->end() |
||
166 | ->scalarNode('audience') |
||
167 | ->cannotBeEmpty() |
||
168 | ->end() |
||
169 | ->end() |
||
170 | ->end() |
||
171 | ->arrayNode('signer') |
||
172 | ->isRequired() |
||
173 | ->beforeNormalization() |
||
174 | ->ifString() |
||
175 | ->then(function (string $config): array { |
||
176 | return ['signing_key' => $config]; |
||
177 | }) |
||
178 | ->end() |
||
179 | ->beforeNormalization() |
||
180 | ->ifTrue(function (?array $config): bool { |
||
181 | $type = $config['type'] ?? self::SIGNER_SYMMETRIC; |
||
182 | |||
183 | return self::SIGNER_ASYMMETRIC === $type; |
||
184 | }) |
||
185 | ->then(function (array $config): array { |
||
186 | if (isset($config['signing_key'])) { |
||
187 | $config['signing_key'] = 'file://' . $config['signing_key']; |
||
188 | } |
||
189 | |||
190 | if (isset($config['verification_key'])) { |
||
191 | $config['verification_key'] = 'file://' . $config['verification_key']; |
||
192 | } |
||
193 | |||
194 | if (!isset($config['algorithm'])) { |
||
195 | $config['algorithm'] = self::ASYMMETRIC_ALGOS[0]; |
||
196 | } |
||
197 | |||
198 | return $config; |
||
199 | }) |
||
200 | ->end() |
||
201 | ->validate() |
||
202 | ->ifTrue(function (array $config): bool { |
||
203 | return self::SIGNER_ASYMMETRIC === $config['type'] && empty($config['verification_key']); |
||
204 | }) |
||
205 | ->thenInvalid('Verification key must be specified for "asymmetric" signer.') |
||
206 | ->end() |
||
207 | ->validate() |
||
208 | ->ifTrue(function (array $config): bool { |
||
209 | return self::SIGNER_SYMMETRIC === $config['type'] && !in_array($config['algorithm'], self::SYMMETRIC_ALGOS); |
||
210 | }) |
||
211 | ->thenInvalid('HMAC algorithm must be specified for "symmetric" signer.') |
||
212 | ->end() |
||
213 | ->validate() |
||
214 | ->ifTrue(function (array $config): bool { |
||
215 | return self::SIGNER_ASYMMETRIC === $config['type'] && !in_array($config['algorithm'], self::ASYMMETRIC_ALGOS); |
||
216 | }) |
||
217 | ->thenInvalid('RSA or ECDSA algorithm must be specified for "asymmetric" signer.') |
||
218 | ->end() |
||
219 | ->validate() |
||
220 | ->ifTrue(function (array $config): bool { |
||
221 | if (self::SIGNER_SYMMETRIC === $config['type']) { |
||
222 | return false; |
||
223 | } |
||
224 | |||
225 | return !is_readable($config['signing_key']) || !is_readable($config['verification_key']); |
||
226 | }) |
||
227 | ->thenInvalid('Signing and/or verification key is not readable.') |
||
228 | ->end() |
||
229 | ->validate() |
||
230 | ->ifTrue(function (array $config): bool { |
||
231 | return self::SIGNER_SYMMETRIC === $config['type'] && !empty($config['verification_key']); |
||
232 | }) |
||
233 | ->thenInvalid('Verification key must no be specified for "symmetric" signer.') |
||
234 | ->end() |
||
235 | ->validate() |
||
236 | ->ifTrue(function (array $config): bool { |
||
237 | return self::SIGNER_SYMMETRIC === $config['type'] && !empty($config['passphrase']); |
||
238 | }) |
||
239 | ->thenInvalid('Passphrase must not be specified for "symmetric" signer.') |
||
240 | ->end() |
||
241 | ->children() |
||
242 | ->enumNode('type') |
||
243 | ->values(['symmetric', 'asymmetric']) |
||
244 | ->defaultValue('symmetric') |
||
245 | ->end() |
||
246 | ->enumNode('algorithm') |
||
247 | ->values(array_merge(self::SYMMETRIC_ALGOS, self::ASYMMETRIC_ALGOS)) |
||
248 | ->defaultValue(self::SYMMETRIC_ALGOS[0]) |
||
249 | ->end() |
||
250 | ->scalarNode('signing_key') |
||
251 | ->isRequired() |
||
252 | ->end() |
||
253 | ->scalarNode('verification_key') |
||
254 | ->cannotBeEmpty() |
||
255 | ->end() |
||
256 | ->scalarNode('passphrase') |
||
257 | ->cannotBeEmpty() |
||
258 | ->defaultValue('') |
||
259 | ->end() |
||
260 | ->end() |
||
261 | ->end() |
||
262 | ->end() |
||
263 | ; |
||
287 |