| Conditions | 2 |
| Paths | 2 |
| Total Lines | 63 |
| Code Lines | 56 |
| 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 |
||
| 85 | protected function continueConfiguration(NodeDefinition $node) |
||
| 86 | { |
||
| 87 | parent::continueConfiguration($node); |
||
| 88 | $node |
||
|
|
|||
| 89 | ->validate() |
||
| 90 | ->ifTrue(function ($config) { |
||
| 91 | return empty($config['default_signature_algorithm']); |
||
| 92 | }) |
||
| 93 | ->thenInvalid('The option "default_signature_algorithm" must be set.') |
||
| 94 | ->end() |
||
| 95 | ->validate() |
||
| 96 | ->ifTrue(function ($config) { |
||
| 97 | return empty($config['signature_algorithms']); |
||
| 98 | }) |
||
| 99 | ->thenInvalid('The option "signature_algorithm" must contain at least one signature algorithm.') |
||
| 100 | ->end() |
||
| 101 | ->validate() |
||
| 102 | ->ifTrue(function ($config) { |
||
| 103 | return !in_array($config['default_signature_algorithm'], $config['signature_algorithms']); |
||
| 104 | }) |
||
| 105 | ->thenInvalid('The default signature algorithm must be in the supported signature algorithms.') |
||
| 106 | ->end() |
||
| 107 | ->validate() |
||
| 108 | ->ifTrue(function ($config) { |
||
| 109 | return empty($config['key_set']); |
||
| 110 | }) |
||
| 111 | ->thenInvalid('The option "key_set" must be set.') |
||
| 112 | ->end() |
||
| 113 | ->children() |
||
| 114 | ->scalarNode('default_signature_algorithm') |
||
| 115 | ->info('Signature algorithm used if the client has not defined a preferred one. Recommended value is "RS256".') |
||
| 116 | ->end() |
||
| 117 | ->scalarNode('key_set') |
||
| 118 | ->info('Key set that contains a suitable signature key for the selected signature algorithms.') |
||
| 119 | ->end() |
||
| 120 | ->arrayNode('signature_algorithms') |
||
| 121 | ->info('Signature algorithm used to sign the ID Tokens.') |
||
| 122 | ->useAttributeAsKey('name') |
||
| 123 | ->prototype('scalar')->end() |
||
| 124 | ->treatNullLike([]) |
||
| 125 | ->end() |
||
| 126 | ->arrayNode('claim_checkers') |
||
| 127 | ->info('Checkers will verify the JWT claims.') |
||
| 128 | ->useAttributeAsKey('name') |
||
| 129 | ->prototype('scalar')->end() |
||
| 130 | ->treatNullLike(['exp', 'iat', 'nbf']) |
||
| 131 | ->end() |
||
| 132 | ->arrayNode('header_checkers') |
||
| 133 | ->info('Checkers will verify the JWT headers.') |
||
| 134 | ->useAttributeAsKey('name') |
||
| 135 | ->prototype('scalar')->end() |
||
| 136 | ->treatNullLike(['crit']) |
||
| 137 | ->end() |
||
| 138 | ->integerNode('lifetime') |
||
| 139 | ->info('Lifetime of the ID Tokens (in seconds). If an access token is issued with the ID Token, the lifetime of the access token is used instead of this value.') |
||
| 140 | ->defaultValue(3600) |
||
| 141 | ->min(1) |
||
| 142 | ->end() |
||
| 143 | ->end(); |
||
| 144 | foreach ($this->subSources as $source) { |
||
| 145 | $source->addConfiguration($node); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 189 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: