| Conditions | 1 |
| Paths | 1 |
| Total Lines | 82 |
| Code Lines | 76 |
| 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 | private function addProvidersSection(ArrayNodeDefinition $rootNode) |
||
| 91 | { |
||
| 92 | /** @var ArrayNodeDefinition $protoType */ |
||
| 93 | $protoType = $rootNode |
||
| 94 | ->children() |
||
| 95 | ->arrayNode('providers') |
||
| 96 | ->isRequired() |
||
| 97 | ->requiresAtLeastOneElement() |
||
| 98 | ->useAttributeAsKey('type') |
||
| 99 | ->prototype('array'); |
||
| 100 | |||
| 101 | $protoType |
||
| 102 | ->canBeDisabled() |
||
| 103 | ->children() |
||
| 104 | ->arrayNode('hosted') |
||
| 105 | ->children() |
||
| 106 | ->arrayNode('service_provider') |
||
| 107 | ->children() |
||
| 108 | ->scalarNode('public_key') |
||
| 109 | ->isRequired() |
||
| 110 | ->info('The absolute path to the public key used to sign AuthnRequests') |
||
| 111 | ->end() |
||
| 112 | ->scalarNode('private_key') |
||
| 113 | ->isRequired() |
||
| 114 | ->info('The absolute path to the private key used to sign AuthnRequests') |
||
| 115 | ->end() |
||
| 116 | ->end() |
||
| 117 | ->end() |
||
| 118 | ->arrayNode('identity_provider') |
||
| 119 | ->children() |
||
| 120 | ->scalarNode('service_provider_repository') |
||
| 121 | ->isRequired() |
||
| 122 | ->info( |
||
| 123 | 'Name of the service that is the Entity Repository. Must implement the ' |
||
| 124 | . ' Surfnet\SamlBundle\Entity\ServiceProviderRepository interface.' |
||
| 125 | ) |
||
| 126 | ->end() |
||
| 127 | ->scalarNode('public_key') |
||
| 128 | ->isRequired() |
||
| 129 | ->info('The absolute path to the public key used to sign Responses to AuthRequests with') |
||
| 130 | ->end() |
||
| 131 | ->scalarNode('private_key') |
||
| 132 | ->isRequired() |
||
| 133 | ->info('The absolute path to the private key used to sign Responses to AuthRequests with') |
||
| 134 | ->end() |
||
| 135 | ->end() |
||
| 136 | ->end() |
||
| 137 | ->arrayNode('metadata') |
||
| 138 | ->children() |
||
| 139 | ->scalarNode('public_key') |
||
| 140 | ->isRequired() |
||
| 141 | ->info('The absolute path to the public key used to sign the metadata') |
||
| 142 | ->end() |
||
| 143 | ->scalarNode('private_key') |
||
| 144 | ->isRequired() |
||
| 145 | ->info('The absolute path to the private key used to sign the metadata') |
||
| 146 | ->end() |
||
| 147 | ->end() |
||
| 148 | ->end() |
||
| 149 | ->end() |
||
| 150 | ->end() |
||
| 151 | ->arrayNode('remote') |
||
| 152 | ->children() |
||
| 153 | ->scalarNode('entity_id') |
||
| 154 | ->isRequired() |
||
| 155 | ->info('The EntityID of the remote identity provider') |
||
| 156 | ->end() |
||
| 157 | ->scalarNode('sso_url') |
||
| 158 | ->isRequired() |
||
| 159 | ->info('The name of the route to generate the SSO URL') |
||
| 160 | ->end() |
||
| 161 | ->scalarNode('certificate') |
||
| 162 | ->isRequired() |
||
| 163 | ->info( |
||
| 164 | 'The contents of the certificate used to sign the AuthnResponse with, if different from' |
||
| 165 | . ' the public key configured below' |
||
| 166 | ) |
||
| 167 | ->end() |
||
| 168 | ->end() |
||
| 169 | ->end() |
||
| 170 | ->end(); |
||
| 171 | } |
||
| 172 | } |
||
| 173 |
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: