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