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