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