| Conditions | 10 |
| Paths | 4 |
| Total Lines | 135 |
| Code Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 84 | public function main(/** @scrutinizer ignore-unused */ SOAP $soap, ServerRequest $request): RunnableResponse |
||
| 85 | { |
||
| 86 | $message = $soap->receive($request); |
||
| 87 | Assert::isInstanceOf($message, AttributeQuery::class, InvalidDOMElement::class); |
||
| 88 | |||
| 89 | $idpEntityId = $this->metadataHandler->getMetaDataCurrentEntityID('saml20-idp-hosted'); |
||
| 90 | |||
| 91 | $issuer = $message->getIssuer(); |
||
| 92 | if ($issuer === null) { |
||
| 93 | throw new Error\BadRequest('Missing <saml:Issuer> in <samlp:AttributeQuery>.'); |
||
| 94 | } else { |
||
| 95 | $spEntityId = $issuer->getContent(); |
||
| 96 | if ($spEntityId === '') { |
||
| 97 | throw new Error\BadRequest('Empty <saml:Issuer> in <samlp:AttributeQuery>.'); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $idpMetadata = $this->metadataHandler->getMetaDataConfig($idpEntityId, 'saml20-idp-hosted'); |
||
| 102 | $spMetadata = $this->metadataHandler->getMetaDataConfig($spEntityId, 'saml20-sp-remote'); |
||
| 103 | |||
| 104 | // The endpoint we should deliver the message to |
||
| 105 | $endpoint = $spMetadata->getString('testAttributeEndpoint'); |
||
| 106 | |||
| 107 | // The attributes we will return |
||
| 108 | $attributes = [ |
||
| 109 | new Attribute( |
||
| 110 | 'name', |
||
| 111 | C::NAMEFORMAT_UNSPECIFIED, |
||
| 112 | null, |
||
| 113 | [ |
||
| 114 | new AttributeValue('value1'), |
||
| 115 | new AttributeValue('value2'), |
||
| 116 | new AttributeValue('value3'), |
||
| 117 | ], |
||
| 118 | ), |
||
| 119 | new Attribute( |
||
| 120 | 'test', |
||
| 121 | C::NAMEFORMAT_UNSPECIFIED, |
||
| 122 | null, |
||
| 123 | [ |
||
| 124 | new AttributeValue('test'), |
||
| 125 | ], |
||
| 126 | ), |
||
| 127 | ]; |
||
| 128 | |||
| 129 | // Determine which attributes we will return |
||
| 130 | // @phpstan-ignore identical.alwaysFalse |
||
| 131 | if (count($attributes) === 0) { |
||
| 132 | Logger::debug('No attributes requested - return all attributes.'); |
||
| 133 | $attributeStatement = null; |
||
| 134 | } else { |
||
| 135 | $returnAttributes = []; |
||
| 136 | foreach ($message->getAttributes() as $reqAttr) { |
||
| 137 | foreach ($attributes as $attr) { |
||
| 138 | if ( |
||
| 139 | $attr->getName() === $reqAttr->getName() |
||
| 140 | && $attr->getNameFormat() === $reqAttr->getNameFormat() |
||
| 141 | ) { |
||
| 142 | // The requested attribute is available |
||
| 143 | if ($reqAttr->getAttributeValues() === []) { |
||
| 144 | // If no specific values are requested, return all |
||
| 145 | $returnAttributes[] = $attr; |
||
| 146 | } else { |
||
| 147 | $returnValues = $this->filterAttributeValues( |
||
| 148 | $reqAttr->getAttributeValues(), |
||
| 149 | $attr->getAttributeValues(), |
||
| 150 | ); |
||
| 151 | |||
| 152 | $returnAttributes[] = new Attribute( |
||
| 153 | $attr->getName(), |
||
| 154 | $attr->getNameFormat(), |
||
| 155 | null, |
||
| 156 | $returnValues, |
||
| 157 | $attr->getAttributesNS(), |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | $attributeStatement = $returnAttributes ? (new AttributeStatement($returnAttributes)) : null; |
||
| 165 | } |
||
| 166 | |||
| 167 | // $returnAttributes contains the attributes we should return. Send them |
||
| 168 | $clock = SAML2_Utils::getContainer()->getClock(); |
||
| 169 | |||
| 170 | $statements = array_filter([$attributeStatement]); |
||
| 171 | $assertion = new Assertion( |
||
| 172 | issuer: new Issuer($idpEntityId), |
||
| 173 | issueInstant: $clock->now(), |
||
| 174 | id: (new Random())->generateID(), |
||
| 175 | subject: new Subject( |
||
| 176 | identifier: $message->getSubject()->getIdentifier(), |
||
| 177 | subjectConfirmation: [ |
||
| 178 | new SubjectConfirmation( |
||
| 179 | method: C::CM_BEARER, |
||
| 180 | subjectConfirmationData: new SubjectConfirmationData( |
||
| 181 | notOnOrAfter: $clock->now()->add(new DateInterval('PT300S')), |
||
| 182 | recipient: $endpoint, |
||
| 183 | inResponseTo: $message->getId(), |
||
| 184 | ), |
||
| 185 | ), |
||
| 186 | ], |
||
| 187 | ), |
||
| 188 | conditions: new Conditions( |
||
| 189 | notBefore: $clock->now(), |
||
| 190 | notOnOrAfter: $clock->now()->add(new DateInterval('PT300S')), |
||
| 191 | audienceRestriction: [ |
||
| 192 | new AudienceRestriction([ |
||
| 193 | new Audience($spEntityId), |
||
| 194 | ]), |
||
| 195 | ], |
||
| 196 | ), |
||
| 197 | statements: $statements, |
||
| 198 | ); |
||
| 199 | |||
| 200 | self::addSign($idpMetadata, $spMetadata, $assertion); |
||
| 201 | |||
| 202 | $response = new Response( |
||
| 203 | status: new Status( |
||
| 204 | new StatusCode(C::STATUS_SUCCESS), |
||
| 205 | ), |
||
| 206 | issueInstant: $clock->now(), |
||
| 207 | issuer: $issuer, |
||
| 208 | id: (new Random())->generateID(), |
||
| 209 | version: '2.0', |
||
| 210 | inResponseTo: $message->getId(), |
||
| 211 | destination: $endpoint, |
||
| 212 | assertions: [$assertion], |
||
| 213 | ); |
||
| 214 | |||
| 215 | self::addSign($idpMetadata, $spMetadata, $response); |
||
| 216 | |||
| 217 | $soap = new SOAP(); |
||
| 218 | return new RunnableResponse([$soap, 'send'], [$response]); |
||
| 219 | } |
||
| 298 |
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