| Conditions | 16 |
| Paths | 206 |
| Total Lines | 122 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 109 | public function receiveResponse(ServerRequestInterface $request): Response |
||
| 110 | { |
||
| 111 | $binding = Binding::getCurrentBinding($request); |
||
| 112 | |||
| 113 | if ($binding instanceof HTTPArtifact) { |
||
| 114 | if ($this->storageProvider === null) { |
||
| 115 | throw new RuntimeException( |
||
| 116 | "A StorageProvider is required to use the HTTP-Artifact binding.", |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | $artifact = $binding->receiveArtifact($request); |
||
| 121 | $this->idpMetadata = $this->metadataProvider->getIdPMetadataForSha1($artifact->getSourceId()); |
||
| 122 | |||
| 123 | if ($this->idpMetadata === null) { |
||
| 124 | throw new MetadataNotFoundException(sprintf( |
||
| 125 | 'No metadata found for remote entity with SHA1 ID: %s', |
||
| 126 | $artifact->getSourceId(), |
||
| 127 | )); |
||
| 128 | } |
||
| 129 | |||
| 130 | $binding->setIdpMetadata($this->idpMetadata); |
||
| 131 | $binding->setSPMetadata($this->spMetadata); |
||
| 132 | } |
||
| 133 | |||
| 134 | $rawResponse = $binding->receive($request); |
||
| 135 | Assert::isInstanceOf($rawResponse, Response::class, ResourceNotRecognizedException::class); // Wrong type of msg |
||
| 136 | |||
| 137 | // Will return a raw Response prior to any form of verification |
||
| 138 | if ($this->bypassResponseVerification === true) { |
||
| 139 | return $rawResponse; |
||
| 140 | } |
||
| 141 | |||
| 142 | // Fetch the metadata for the remote entity |
||
| 143 | if (!($binding instanceof HTTPArtifact)) { |
||
| 144 | $this->idpMetadata = $this->metadataProvider->getIdPMetadata($rawResponse->getIssuer()->getContent()); |
||
| 145 | |||
| 146 | if ($this->idpMetadata === null) { |
||
| 147 | throw new MetadataNotFoundException(sprintf( |
||
| 148 | 'No metadata found for remote entity with entityID: %s', |
||
| 149 | $rawResponse->getIssuer()->getContent(), |
||
| 150 | )); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | // Verify the signature (if any) |
||
| 155 | $verifiedResponse = $rawResponse->isSigned() ? $this->verifyElementSignature($rawResponse) : $rawResponse; |
||
| 156 | |||
| 157 | $state = null; |
||
| 158 | $stateId = $verifiedResponse->getInResponseTo(); |
||
| 159 | |||
| 160 | if (!empty($stateId)) { |
||
| 161 | if ($this->stateProvider === null) { |
||
| 162 | throw new RuntimeException( |
||
| 163 | "A StateProvider is required to correlate responses to their initial request.", |
||
| 164 | ); |
||
| 165 | } |
||
| 166 | |||
| 167 | // this should be a response to a request we sent earlier |
||
| 168 | try { |
||
| 169 | $state = $this->stateProvider::loadState($stateId, 'saml:sp:sso'); |
||
| 170 | } catch (RuntimeException $e) { |
||
| 171 | // something went wrong, |
||
| 172 | Utils::getContainer()->getLogger()->warning(sprintf( |
||
| 173 | 'Could not load state specified by InResponseTo: %s; processing response as unsolicited.', |
||
| 174 | $e->getMessage(), |
||
| 175 | )); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | $issuer = $verifiedResponse->getIssuer()->getContent(); |
||
| 180 | if ($state === null) { |
||
| 181 | if ($this->enableUnsolicited === false) { |
||
| 182 | throw new RequestDeniedException('Unsolicited responses are denied by configuration.'); |
||
| 183 | } |
||
| 184 | } else { |
||
| 185 | // check that the issuer is the one we are expecting |
||
| 186 | Assert::keyExists($state, 'ExpectedIssuer'); |
||
| 187 | |||
| 188 | if ($state['ExpectedIssuer'] !== $issuer) { |
||
| 189 | throw new ResourceNotRecognizedException("Issuer doesn't match the one the AuthnRequest was sent to."); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | $this->idpMetadata = $this->metadataProvider->getIdPMetadata($issuer); |
||
| 194 | if ($this->idpMetadata === null) { |
||
| 195 | throw new MetadataNotFoundException(sprintf( |
||
| 196 | 'No metadata found for remote identity provider with entityID: %s', |
||
| 197 | $issuer, |
||
| 198 | )); |
||
| 199 | } |
||
| 200 | |||
| 201 | $responseValidator = ResponseValidator::createResponseValidator( |
||
| 202 | $this->idpMetadata, |
||
| 203 | $this->spMetadata, |
||
| 204 | $binding, |
||
| 205 | ); |
||
| 206 | $responseValidator->validate($verifiedResponse); |
||
| 207 | |||
| 208 | // Decrypt and verify assertions, then rebuild the response. |
||
| 209 | $verifiedAssertions = $this->decryptAndVerifyAssertions($verifiedResponse->getAssertions()); |
||
| 210 | $decryptedResponse = new Response( |
||
| 211 | $verifiedResponse->getStatus(), |
||
| 212 | $verifiedResponse->getIssueInstant(), |
||
| 213 | $verifiedResponse->getIssuer(), |
||
| 214 | $verifiedResponse->getID(), |
||
| 215 | $verifiedResponse->getVersion(), |
||
| 216 | $verifiedResponse->getInResponseTo(), |
||
| 217 | $verifiedResponse->getDestination(), |
||
| 218 | $verifiedResponse->getConsent(), |
||
| 219 | $verifiedResponse->getExtensions(), |
||
| 220 | $verifiedAssertions, |
||
| 221 | ); |
||
| 222 | |||
| 223 | |||
| 224 | // Will return a verified and fully decrypted Response prior to any form of validation |
||
| 225 | if ($this->bypassConstraintValidation === true) { |
||
| 226 | return $decryptedResponse; |
||
| 227 | } |
||
| 228 | |||
| 229 | // TODO: Validate assertions |
||
| 230 | return $decryptedResponse; |
||
| 231 | } |
||
| 358 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths