| Conditions | 9 |
| Paths | 6 |
| Total Lines | 96 |
| Code Lines | 62 |
| 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 |
||
| 75 | public function main(/** @scrutinizer ignore-unused */ Request $request): RunnableResponse |
||
| 76 | { |
||
| 77 | $binding = Binding::getCurrentBinding(); |
||
| 78 | $query = $binding->receive(); |
||
| 79 | if (!($query instanceof AttributeQuery)) { |
||
| 80 | throw new Error\BadRequest('Invalid message received to AttributeQuery endpoint.'); |
||
| 81 | } |
||
| 82 | |||
| 83 | $idpEntityId = $this->metadataHandler->getMetaDataCurrentEntityID('saml20-idp-hosted'); |
||
|
|
|||
| 84 | |||
| 85 | $issuer = $query->getIssuer(); |
||
| 86 | if ($issuer === null) { |
||
| 87 | throw new Error\BadRequest('Missing <saml:Issuer> in <samlp:AttributeQuery>.'); |
||
| 88 | } else { |
||
| 89 | $spEntityId = $issuer->getValue(); |
||
| 90 | if ($spEntityId === '') { |
||
| 91 | throw new Error\BadRequest('Empty <saml:Issuer> in <samlp:AttributeQuery>.'); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | $idpMetadata = $this->metadataHandler->getMetaDataConfig($idpEntityId, 'saml20-idp-hosted'); |
||
| 96 | $spMetadata = $this->metadataHandler->getMetaDataConfig($spEntityId, 'saml20-sp-remote'); |
||
| 97 | |||
| 98 | // The endpoint we should deliver the message to |
||
| 99 | $endpoint = $spMetadata->getString('testAttributeEndpoint'); |
||
| 100 | |||
| 101 | // The attributes we will return |
||
| 102 | $attributes = [ |
||
| 103 | 'name' => ['value1', 'value2', 'value3'], |
||
| 104 | 'test' => ['test'], |
||
| 105 | ]; |
||
| 106 | |||
| 107 | // The name format of the attributes |
||
| 108 | $attributeNameFormat = Constants::NAMEFORMAT_UNSPECIFIED; |
||
| 109 | |||
| 110 | // Determine which attributes we will return |
||
| 111 | $returnAttributes = array_keys($query->getAttributes()); |
||
| 112 | if (count($returnAttributes) === 0) { |
||
| 113 | Logger::debug('No attributes requested - return all attributes.'); |
||
| 114 | $returnAttributes = $attributes; |
||
| 115 | } elseif ($query->getAttributeNameFormat() !== $attributeNameFormat) { |
||
| 116 | Logger::debug('Requested attributes with wrong NameFormat - no attributes returned.'); |
||
| 117 | $returnAttributes = []; |
||
| 118 | } else { |
||
| 119 | /** @var array $values */ |
||
| 120 | foreach ($returnAttributes as $name => $values) { |
||
| 121 | if (!array_key_exists($name, $attributes)) { |
||
| 122 | // We don't have this attribute |
||
| 123 | unset($returnAttributes[$name]); |
||
| 124 | continue; |
||
| 125 | } |
||
| 126 | if (count($values) === 0) { |
||
| 127 | // Return all attributes |
||
| 128 | $returnAttributes[$name] = $attributes[$name]; |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | |||
| 132 | // Filter which attribute values we should return |
||
| 133 | $returnAttributes[$name] = array_intersect($values, $attributes[$name]); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | // $returnAttributes contains the attributes we should return. Send them |
||
| 138 | $issuer = new Issuer(); |
||
| 139 | $issuer->setValue($idpEntityId); |
||
| 140 | |||
| 141 | $assertion = new Assertion(); |
||
| 142 | $assertion->setIssuer($issuer); |
||
| 143 | $assertion->setNameId($query->getNameId()); |
||
| 144 | $assertion->setNotBefore(time()); |
||
| 145 | $assertion->setNotOnOrAfter(time() + 300); // 60*5 = 5min |
||
| 146 | $assertion->setValidAudiences([$spEntityId]); |
||
| 147 | $assertion->setAttributes($returnAttributes); |
||
| 148 | $assertion->setAttributeNameFormat($attributeNameFormat); |
||
| 149 | |||
| 150 | $sc = new SubjectConfirmation(); |
||
| 151 | $sc->setMethod(Constants::CM_BEARER); |
||
| 152 | |||
| 153 | $scd = new SubjectConfirmationData(); |
||
| 154 | $scd->setNotOnOrAfter(time() + 300); // 60*5 = 5min |
||
| 155 | $scd->setRecipient($endpoint); |
||
| 156 | $scd->setInResponseTo($query->getId()); |
||
| 157 | $sc->setSubjectConfirmationData($scd); |
||
| 158 | $assertion->setSubjectConfirmation([$sc]); |
||
| 159 | |||
| 160 | Message::addSign($idpMetadata, $spMetadata, $assertion); |
||
| 161 | |||
| 162 | $response = new Response(); |
||
| 163 | $response->setRelayState($query->getRelayState()); |
||
| 164 | $response->setDestination($endpoint); |
||
| 165 | $response->setIssuer($issuer); |
||
| 166 | $response->setInResponseTo($query->getId()); |
||
| 167 | $response->setAssertions([$assertion]); |
||
| 168 | Message::addSign($idpMetadata, $spMetadata, $response); |
||
| 169 | |||
| 170 | return new RunnableResponse([new HTTPPost(), 'send'], [$response]); |
||
| 171 | } |
||
| 173 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.