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