| Conditions | 4 |
| Paths | 1 |
| Total Lines | 74 |
| Code Lines | 69 |
| 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 |
||
| 50 | public function getNodeDefinition(NodeDefinition $node) |
||
| 51 | { |
||
| 52 | $node->children() |
||
|
|
|||
| 53 | ->arrayNode($this->name()) |
||
| 54 | ->addDefaultsIfNotSet() |
||
| 55 | ->canBeEnabled() |
||
| 56 | ->info('This method comprises the "client_secret_jwt" and the "private_key_jwt" authentication methods') |
||
| 57 | ->validate() |
||
| 58 | ->ifTrue(function ($config) { |
||
| 59 | return true === $config['enabled'] && empty($config['signature_algorithms']); |
||
| 60 | }) |
||
| 61 | ->thenInvalid('At least one signature algorithm must be set.') |
||
| 62 | ->end() |
||
| 63 | ->children() |
||
| 64 | ->integerNode('secret_lifetime') |
||
| 65 | ->info('Secret lifetime (in seconds; 0 = unlimited) applicable to the "client_secret_jwt" authentication method') |
||
| 66 | ->defaultValue(60 * 60 * 24 * 14) |
||
| 67 | ->min(0) |
||
| 68 | ->end() |
||
| 69 | ->arrayNode('signature_algorithms') |
||
| 70 | ->info('Supported signature algorithms.') |
||
| 71 | ->useAttributeAsKey('name') |
||
| 72 | ->prototype('scalar')->end() |
||
| 73 | ->treatNullLike([]) |
||
| 74 | ->end() |
||
| 75 | ->arrayNode('claim_checkers') |
||
| 76 | ->info('Claim checkers for incoming assertions.') |
||
| 77 | ->useAttributeAsKey('name') |
||
| 78 | ->prototype('scalar')->end() |
||
| 79 | ->treatNullLike([]) |
||
| 80 | ->end() |
||
| 81 | ->arrayNode('header_checkers') |
||
| 82 | ->info('Header checkers for incoming assertions.') |
||
| 83 | ->useAttributeAsKey('name') |
||
| 84 | ->prototype('scalar')->end() |
||
| 85 | ->treatNullLike([]) |
||
| 86 | ->end() |
||
| 87 | ->arrayNode('encryption') |
||
| 88 | ->canBeEnabled() |
||
| 89 | ->validate() |
||
| 90 | ->ifTrue(function ($config) { |
||
| 91 | return true === $config['enabled'] && empty($config['key_encryption_algorithms']); |
||
| 92 | }) |
||
| 93 | ->thenInvalid('At least one key encryption algorithm must be set.') |
||
| 94 | ->end() |
||
| 95 | ->validate() |
||
| 96 | ->ifTrue(function ($config) { |
||
| 97 | return true === $config['enabled'] && empty($config['content_encryption_algorithms']); |
||
| 98 | }) |
||
| 99 | ->thenInvalid('At least one content encryption algorithm must be set.') |
||
| 100 | ->end() |
||
| 101 | ->children() |
||
| 102 | ->booleanNode('required') |
||
| 103 | ->info('When true, all incoming assertions must be encrypted.') |
||
| 104 | ->defaultFalse() |
||
| 105 | ->end() |
||
| 106 | ->arrayNode('key_encryption_algorithms') |
||
| 107 | ->info('Supported key encryption algorithms.') |
||
| 108 | ->useAttributeAsKey('name') |
||
| 109 | ->prototype('scalar')->end() |
||
| 110 | ->treatNullLike([]) |
||
| 111 | ->end() |
||
| 112 | ->arrayNode('content_encryption_algorithms') |
||
| 113 | ->info('Supported content encryption algorithms.') |
||
| 114 | ->useAttributeAsKey('name') |
||
| 115 | ->prototype('scalar')->end() |
||
| 116 | ->treatNullLike([]) |
||
| 117 | ->end() |
||
| 118 | ->end() |
||
| 119 | ->end() |
||
| 120 | ->end() |
||
| 121 | ->end() |
||
| 122 | ->end(); |
||
| 123 | } |
||
| 124 | |||
| 133 |
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: