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