Conditions | 4 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 46 |
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 |
||
90 | protected function continueConfiguration(NodeDefinition $node) |
||
91 | { |
||
92 | parent::continueConfiguration($node); |
||
93 | $node |
||
|
|||
94 | ->validate() |
||
95 | ->ifTrue(function ($config) { |
||
96 | return true === $config['enabled'] && empty($config['signature_algorithms']); |
||
97 | }) |
||
98 | ->thenInvalid('The option "signature_algorithm" must contain at least one signature algorithm.') |
||
99 | ->end() |
||
100 | ->validate() |
||
101 | ->ifTrue(function ($config) { |
||
102 | return true === $config['enabled'] && empty($config['key_set']); |
||
103 | }) |
||
104 | ->thenInvalid('The option "key_set" must be set.') |
||
105 | ->end() |
||
106 | ->children() |
||
107 | ->scalarNode('default_signature_algorithm') |
||
108 | ->info('Signature algorithm used if the client has not defined a preferred one. Recommended value is "RS256".') |
||
109 | ->end() |
||
110 | ->scalarNode('key_set') |
||
111 | ->info('Key set that contains a suitable signature key for the selected signature algorithms.') |
||
112 | ->end() |
||
113 | ->arrayNode('signature_algorithms') |
||
114 | ->info('Signature algorithm used to sign the ID Tokens.') |
||
115 | ->useAttributeAsKey('name') |
||
116 | ->prototype('scalar')->end() |
||
117 | ->treatNullLike([]) |
||
118 | ->end() |
||
119 | ->arrayNode('claim_checkers') |
||
120 | ->info('Checkers will verify the JWT claims.') |
||
121 | ->useAttributeAsKey('name') |
||
122 | ->prototype('scalar')->end() |
||
123 | ->treatNullLike(['exp', 'iat', 'nbf']) |
||
124 | ->end() |
||
125 | ->arrayNode('header_checkers') |
||
126 | ->info('Checkers will verify the JWT headers.') |
||
127 | ->useAttributeAsKey('name') |
||
128 | ->prototype('scalar')->end() |
||
129 | ->treatNullLike(['crit']) |
||
130 | ->end() |
||
131 | ->integerNode('lifetime') |
||
132 | ->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.') |
||
133 | ->defaultValue(3600) |
||
134 | ->min(1) |
||
135 | ->end() |
||
136 | ->end(); |
||
137 | foreach ($this->subSources as $source) { |
||
138 | $source->addConfiguration($node); |
||
139 | } |
||
140 | } |
||
141 | |||
195 |
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: