| 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 |
||
| 70 | private function jwtNode(string $name): ArrayNodeDefinition |
||
| 71 | { |
||
| 72 | return (new ArrayNodeDefinition($name)) |
||
| 73 | ->beforeNormalization() |
||
| 74 | ->ifString() |
||
| 75 | ->then(function (string $config): array { |
||
| 76 | return ['signer' => $config]; |
||
| 77 | }) |
||
| 78 | ->end() |
||
| 79 | ->canBeEnabled() |
||
|
1 ignored issue
–
show
|
|||
| 80 | ->children() |
||
| 81 | ->append($this->extractorsNode('extractors', [ |
||
| 82 | [ |
||
| 83 | 'type' => 'header', |
||
| 84 | 'name' => 'Authorization', |
||
| 85 | 'prefix' => 'Bearer', |
||
| 86 | ], |
||
| 87 | ])) |
||
| 88 | ->scalarNode('identity_claim') |
||
| 89 | ->cannotBeEmpty() |
||
| 90 | ->end() |
||
| 91 | ->arrayNode('builder') |
||
| 92 | ->addDefaultsIfNotSet() |
||
| 93 | ->children() |
||
| 94 | ->scalarNode('issuer') |
||
| 95 | ->cannotBeEmpty() |
||
| 96 | ->end() |
||
| 97 | ->scalarNode('audience') |
||
| 98 | ->cannotBeEmpty() |
||
| 99 | ->end() |
||
| 100 | ->integerNode('ttl') |
||
| 101 | ->defaultValue(3600) |
||
| 102 | ->end() |
||
| 103 | ->end() |
||
| 104 | ->end() |
||
| 105 | ->arrayNode('parser') |
||
| 106 | ->children() |
||
| 107 | ->arrayNode('issuers') |
||
| 108 | ->requiresAtLeastOneElement() |
||
| 109 | ->prototype('scalar') |
||
| 110 | ->isRequired() |
||
| 111 | ->end() |
||
| 112 | ->end() |
||
| 113 | ->scalarNode('audience') |
||
| 114 | ->cannotBeEmpty() |
||
| 115 | ->end() |
||
| 116 | ->end() |
||
| 117 | ->end() |
||
| 118 | ->arrayNode('signer') |
||
| 119 | ->isRequired() |
||
| 120 | ->beforeNormalization() |
||
| 121 | ->ifString() |
||
| 122 | ->then(function (string $config): array { |
||
| 123 | return ['signing_key' => $config]; |
||
| 124 | }) |
||
| 125 | ->end() |
||
| 126 | ->beforeNormalization() |
||
| 127 | ->ifTrue(function (?array $config): bool { |
||
| 128 | $type = $config['type'] ?? self::SIGNER_SYMMETRIC; |
||
| 129 | |||
| 130 | return self::SIGNER_ASYMMETRIC === $type; |
||
| 131 | }) |
||
| 132 | ->then(function (array $config): array { |
||
| 133 | if (isset($config['signing_key'])) { |
||
| 134 | $config['signing_key'] = 'file://' . $config['signing_key']; |
||
| 135 | } |
||
| 136 | |||
| 137 | if (isset($config['verification_key'])) { |
||
| 138 | $config['verification_key'] = 'file://' . $config['verification_key']; |
||
| 139 | } |
||
| 140 | |||
| 141 | if (!isset($config['algorithm'])) { |
||
| 142 | $config['algorithm'] = self::ASYMMETRIC_ALGOS[0]; |
||
| 143 | } |
||
| 144 | |||
| 145 | return $config; |
||
| 146 | }) |
||
| 147 | ->end() |
||
| 148 | ->validate() |
||
| 149 | ->ifTrue(function (array $config): bool { |
||
| 150 | return self::SIGNER_ASYMMETRIC === $config['type'] && empty($config['verification_key']); |
||
| 151 | }) |
||
| 152 | ->thenInvalid('Verification key must be specified for "asymmetric" signer.') |
||
| 153 | ->end() |
||
| 154 | ->validate() |
||
| 155 | ->ifTrue(function (array $config): bool { |
||
| 156 | return self::SIGNER_SYMMETRIC === $config['type'] && !in_array($config['algorithm'], self::SYMMETRIC_ALGOS); |
||
| 157 | }) |
||
| 158 | ->thenInvalid('HMAC algorithm must be specified for "symmetric" signer.') |
||
| 159 | ->end() |
||
| 160 | ->validate() |
||
| 161 | ->ifTrue(function (array $config): bool { |
||
| 162 | return self::SIGNER_ASYMMETRIC === $config['type'] && !in_array($config['algorithm'], self::ASYMMETRIC_ALGOS); |
||
| 163 | }) |
||
| 164 | ->thenInvalid('RSA or ECDSA algorithm must be specified for "asymmetric" signer.') |
||
| 165 | ->end() |
||
| 166 | ->validate() |
||
| 167 | ->ifTrue(function (array $config): bool { |
||
| 168 | if (self::SIGNER_SYMMETRIC === $config['type']) { |
||
| 169 | return false; |
||
| 170 | } |
||
| 171 | |||
| 172 | return !is_readable($config['signing_key']) || !is_readable($config['verification_key']); |
||
| 173 | }) |
||
| 174 | ->thenInvalid('Signing and/or verification key is not readable.') |
||
| 175 | ->end() |
||
| 176 | ->validate() |
||
| 177 | ->ifTrue(function (array $config): bool { |
||
| 178 | return self::SIGNER_SYMMETRIC === $config['type'] && !empty($config['verification_key']); |
||
| 179 | }) |
||
| 180 | ->thenInvalid('Verification key must no be specified for "symmetric" signer.') |
||
| 181 | ->end() |
||
| 182 | ->validate() |
||
| 183 | ->ifTrue(function (array $config): bool { |
||
| 184 | return self::SIGNER_SYMMETRIC === $config['type'] && !empty($config['passphrase']); |
||
| 185 | }) |
||
| 186 | ->thenInvalid('Passphrase must not be specified for "symmetric" signer.') |
||
| 187 | ->end() |
||
| 188 | ->children() |
||
| 189 | ->enumNode('type') |
||
| 190 | ->values(['symmetric', 'asymmetric']) |
||
| 191 | ->defaultValue('symmetric') |
||
| 192 | ->end() |
||
| 193 | ->enumNode('algorithm') |
||
| 194 | ->values(array_merge(self::SYMMETRIC_ALGOS, self::ASYMMETRIC_ALGOS)) |
||
| 195 | ->defaultValue(self::SYMMETRIC_ALGOS[0]) |
||
| 196 | ->end() |
||
| 197 | ->scalarNode('signing_key') |
||
| 198 | ->isRequired() |
||
| 199 | ->end() |
||
| 200 | ->scalarNode('verification_key') |
||
| 201 | ->cannotBeEmpty() |
||
| 202 | ->end() |
||
| 203 | ->scalarNode('passphrase') |
||
| 204 | ->cannotBeEmpty() |
||
| 205 | ->defaultValue('') |
||
| 206 | ->end() |
||
| 207 | ->end() |
||
| 208 | ->end() |
||
| 209 | ->end() |
||
| 210 | ; |
||
| 252 |