| Conditions | 5 |
| Paths | 16 |
| Total Lines | 102 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 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 |
||
| 103 | public function validateInstitutionConfigurationOptions(array $options, string $institution): void |
||
| 104 | { |
||
| 105 | $propertyPath = sprintf('Institution(%s)', $institution); |
||
| 106 | $requiredOptions = [ |
||
| 107 | 'use_ra_locations', |
||
| 108 | 'show_raa_contact_information', |
||
| 109 | 'verify_email', |
||
| 110 | 'number_of_tokens_per_identity', |
||
| 111 | 'allowed_second_factors', |
||
| 112 | ]; |
||
| 113 | $optionalOptions = [ |
||
| 114 | 'self_vet', |
||
| 115 | 'sso_on_2fa', |
||
| 116 | 'sso_registration_bypass', |
||
| 117 | 'allow_self_asserted_tokens', |
||
| 118 | 'use_ra', |
||
| 119 | 'use_raa', |
||
| 120 | 'select_raa', |
||
| 121 | ]; |
||
| 122 | StepupAssert::requiredAndOptionalOptions( |
||
| 123 | $options, |
||
| 124 | $requiredOptions, |
||
| 125 | $optionalOptions, |
||
| 126 | sprintf( |
||
| 127 | 'Invalid option(s) for "%s". Required options: "%s"; Optional options: "%s"', |
||
| 128 | $institution, |
||
| 129 | implode(', ', $requiredOptions), |
||
| 130 | implode(', ', $optionalOptions), |
||
| 131 | ), |
||
| 132 | $propertyPath, |
||
| 133 | ); |
||
| 134 | Assertion::boolean( |
||
| 135 | $options['use_ra_locations'], |
||
| 136 | sprintf('Option "use_ra_locations" for "%s" must be a boolean value', $institution), |
||
| 137 | $propertyPath, |
||
| 138 | ); |
||
| 139 | Assertion::boolean( |
||
| 140 | $options['show_raa_contact_information'], |
||
| 141 | sprintf('Option "show_raa_contact_information" for "%s" must be a boolean value', $institution), |
||
| 142 | $propertyPath, |
||
| 143 | ); |
||
| 144 | Assertion::boolean( |
||
| 145 | $options['verify_email'], |
||
| 146 | sprintf('Option "verify_email" for "%s" must be a boolean value', $institution), |
||
| 147 | $propertyPath, |
||
| 148 | ); |
||
| 149 | if (isset($options['self_vet'])) { |
||
| 150 | Assertion::boolean( |
||
| 151 | $options['self_vet'], |
||
| 152 | sprintf('Option "self_vet" for "%s" must be a boolean value', $institution), |
||
| 153 | $propertyPath, |
||
| 154 | ); |
||
| 155 | } |
||
| 156 | if (isset($options['sso_on_2fa'])) { |
||
| 157 | Assertion::boolean( |
||
| 158 | $options['sso_on_2fa'], |
||
| 159 | sprintf('Option "sso_on_2fa" for "%s" must be a boolean value', $institution), |
||
| 160 | $propertyPath, |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | if (isset($options['sso_registration_bypass'])) { |
||
| 164 | Assertion::boolean( |
||
| 165 | $options['sso_registration_bypass'], |
||
| 166 | sprintf('Option "sso_registration_bypass" for "%s" must be a boolean value', $institution), |
||
| 167 | $propertyPath, |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | if (isset($options['allow_self_asserted_tokens'])) { |
||
| 171 | Assertion::nullOrBoolean( |
||
| 172 | $options['allow_self_asserted_tokens'], |
||
| 173 | sprintf('Option "allow_self_asserted_tokens" for "%s" must be a boolean value', $institution), |
||
| 174 | $propertyPath, |
||
| 175 | ); |
||
| 176 | } |
||
| 177 | Assertion::integer( |
||
| 178 | $options['number_of_tokens_per_identity'], |
||
| 179 | sprintf('Option "number_of_tokens_per_identity" for "%s" must be an integer value', $institution), |
||
| 180 | $propertyPath, |
||
| 181 | ); |
||
| 182 | Assertion::min( |
||
| 183 | $options['number_of_tokens_per_identity'], |
||
| 184 | 0, |
||
| 185 | sprintf('Option "number_of_tokens_per_identity" for "%s" must be greater than or equal to 0', $institution), |
||
| 186 | $propertyPath, |
||
| 187 | ); |
||
| 188 | Assertion::isArray( |
||
| 189 | $options['allowed_second_factors'], |
||
| 190 | sprintf('Option "allowed_second_factors" for "%s" must be an array of strings', $institution), |
||
| 191 | $propertyPath, |
||
| 192 | ); |
||
| 193 | Assertion::allString( |
||
| 194 | $options['allowed_second_factors'], |
||
| 195 | sprintf('Option "allowed_second_factors" for "%s" must be an array of strings', $institution), |
||
| 196 | $propertyPath, |
||
| 197 | ); |
||
| 198 | Assertion::allInArray( |
||
| 199 | $options['allowed_second_factors'], |
||
| 200 | $this->secondFactorTypeService->getAvailableSecondFactorTypes(), |
||
| 201 | 'Option "allowed_second_factors" for "%s" must contain valid second factor types', |
||
| 202 | $propertyPath, |
||
| 203 | ); |
||
| 204 | $this->validateAuthorizationSettings($options, $institution, $propertyPath); |
||
| 205 | } |
||
| 330 |