| Conditions | 2 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 50 |
| 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 |
||
| 47 | public function getNodeDefinition(NodeDefinition $node) |
||
| 48 | { |
||
| 49 | $node |
||
|
|
|||
| 50 | ->validate() |
||
| 51 | ->ifTrue(function ($config) { |
||
| 52 | return true === $config['enabled'] && empty($config['signature_algorithms']); |
||
| 53 | }) |
||
| 54 | ->thenInvalid('The option "signature_algorithms" must contain at least one signature algorithm.') |
||
| 55 | ->end() |
||
| 56 | ->children() |
||
| 57 | ->booleanNode('issue_refresh_token') |
||
| 58 | ->info('If true, a refresh token will be issued with the access token (the refresh token grant type must be enabled).') |
||
| 59 | ->end() |
||
| 60 | ->arrayNode('signature_algorithms') |
||
| 61 | ->info('Signature algorithms supported by this grant type.') |
||
| 62 | ->useAttributeAsKey('name') |
||
| 63 | ->prototype('scalar')->end() |
||
| 64 | ->treatNullLike([]) |
||
| 65 | ->end() |
||
| 66 | ->arrayNode('claim_checkers') |
||
| 67 | ->info('Checkers will verify the JWT claims.') |
||
| 68 | ->useAttributeAsKey('name') |
||
| 69 | ->prototype('scalar')->end() |
||
| 70 | ->treatNullLike(['exp', 'iat', 'nbf']) |
||
| 71 | ->end() |
||
| 72 | ->arrayNode('header_checkers') |
||
| 73 | ->info('Checkers will verify the JWT headers.') |
||
| 74 | ->useAttributeAsKey('name') |
||
| 75 | ->prototype('scalar')->end() |
||
| 76 | ->treatNullLike(['crit']) |
||
| 77 | ->end() |
||
| 78 | ->arrayNode('encryption') |
||
| 79 | ->children() |
||
| 80 | ->booleanNode('required') |
||
| 81 | ->info('If set to true, all ID Token sent to the server must be encrypted.') |
||
| 82 | ->defaultFalse() |
||
| 83 | ->end() |
||
| 84 | ->arrayNode('key_encryption_algorithms') |
||
| 85 | ->info('Supported key encryption algorithms.') |
||
| 86 | ->useAttributeAsKey('name') |
||
| 87 | ->prototype('scalar')->end() |
||
| 88 | ->treatNullLike([]) |
||
| 89 | ->end() |
||
| 90 | ->arrayNode('content_encryption_algorithms') |
||
| 91 | ->info('Supported content encryption algorithms.') |
||
| 92 | ->useAttributeAsKey('name') |
||
| 93 | ->prototype('scalar')->end() |
||
| 94 | ->treatNullLike([]) |
||
| 95 | ->end() |
||
| 96 | ->end() |
||
| 97 | ->end() |
||
| 98 | ->end(); |
||
| 99 | } |
||
| 100 | |||
| 132 |
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: