Conditions | 1 |
Paths | 1 |
Total Lines | 91 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
232 | public function registerProvider() |
||
233 | { |
||
234 | // phpcs:disable |
||
235 | $testSource = PublicKeyCredentialSource::createFromArray([ |
||
236 | 'publicKeyCredentialId' => 'g8e1UH4B1gUYl_7AiDXHTp8SE3cxYnpC6jF3Fo0KMm79FNN_e34hDE1Mnd4FSOoNW6B-p7xB2tqj28svkJQh1Q', |
||
237 | 'type' => 'public-key', |
||
238 | 'transports' => [], |
||
239 | 'attestationType' => 'none', |
||
240 | 'trustPath' => [ |
||
241 | 'type' => 'empty', |
||
242 | ], |
||
243 | 'aaguid' => 'AAAAAAAAAAAAAAAAAAAAAA', |
||
244 | 'credentialPublicKey' => 'pQECAyYgASFYII3gDdvOBje5JfjNO0VhxE2RrV5XoKqWmCZAmR0f9nFaIlggZOUvkovGH9cfeyfXEpJAVOzR1d-rVRZJvwWJf444aLo', |
||
245 | 'userHandle' => 'MQ', |
||
246 | 'counter' => 268, |
||
247 | ]); |
||
248 | // phpcs:enable |
||
249 | |||
250 | $authDataMock = $this->createMock(AuthenticatorData::class); |
||
251 | $authDataMock->expects($this->exactly(4))->method('hasAttestedCredentialData') |
||
252 | // The first call is the "response indicates incomplete data" test case, second is "valid response", |
||
253 | // third is "invalid response" |
||
254 | ->willReturnOnConsecutiveCalls(false, true, true, true); |
||
255 | $authDataMock->expects($this->any())->method('getAttestedCredentialData')->willReturn( |
||
256 | $testSource->getAttestedCredentialData() |
||
257 | ); |
||
258 | $authDataMock->expects($this->any())->method('getSignCount')->willReturn(1); |
||
259 | |||
260 | $attestationMock = $this->createMock(AttestationObject::class); |
||
261 | $attestationMock->expects($this->any())->method('getAuthData')->willReturn($authDataMock); |
||
262 | |||
263 | $responseMock = $this->createMock(AuthenticatorAttestationResponse::class); |
||
264 | $responseMock->expects($this->any())->method('getAttestationObject')->willReturn($attestationMock); |
||
265 | |||
266 | return [ |
||
267 | 'wrong response return type' => [ |
||
268 | // Deliberately the wrong child implementation of \Webauthn\AuthenticatorResponse |
||
269 | $this->createMock(AuthenticatorAssertionResponse::class), |
||
270 | new Result(false, 'Unexpected response type found'), |
||
271 | 0, |
||
272 | ], |
||
273 | 'response indicates incomplete data' => [ |
||
274 | $responseMock, |
||
275 | new Result(false, 'Incomplete data, required information missing'), |
||
276 | 0, |
||
277 | ], |
||
278 | 'valid response' => [ |
||
279 | $responseMock, |
||
280 | new Result(true), |
||
281 | 1, |
||
282 | function (PHPUnit_Framework_MockObject_MockObject $responseValidatorMock) { |
||
283 | // Specifically setting expectations for the result of the response validator's "check" call |
||
284 | $responseValidatorMock->expects($this->once())->method('check')->willReturn(true); |
||
285 | }, |
||
286 | ], |
||
287 | 'valid response with existing credential' => [ |
||
288 | $responseMock, |
||
289 | new Result(true), |
||
290 | 1, |
||
291 | function (PHPUnit_Framework_MockObject_MockObject $responseValidatorMock) { |
||
292 | // Specifically setting expectations for the result of the response validator's "check" call |
||
293 | $responseValidatorMock->expects($this->once())->method('check')->willReturn(true); |
||
294 | }, |
||
295 | function (SessionStore $store) use ($testSource) { |
||
|
|||
296 | $repo = new CredentialRepository((string) $store->getMember()->ID); |
||
297 | // phpcs:disable |
||
298 | $repo->saveCredentialSource(PublicKeyCredentialSource::createFromArray([ |
||
299 | 'publicKeyCredentialId' => 'g8e1UH4B1gUYl_7AiDXHTp8SE3cxYnpC6jF3Fo0KMm79FNN_e34hDE1Mnd4FSOoNW245125129518925891', |
||
300 | 'type' => 'public-key', |
||
301 | 'transports' => [], |
||
302 | 'attestationType' => 'none', |
||
303 | 'trustPath' => [ |
||
304 | 'type' => 'empty', |
||
305 | ], |
||
306 | 'aaguid' => 'AAAAAAAAAAAAAAAAAAAAAA', |
||
307 | 'credentialPublicKey' => 'pQECAyYgASFYII3gDdvOBje5JfjNO0VhxE2RrV5XoKqWmCZAmR0f9nFaIlggZOUvkovGH9cfeyfXEpJAVOzR1d-rVRZJvwWJf444aLo', |
||
308 | 'userHandle' => 'MQ', |
||
309 | 'counter' => 268, |
||
310 | ])); |
||
311 | // phpcs:enable |
||
312 | $store->addState(['repository' => $repo]); |
||
313 | }, |
||
314 | ], |
||
315 | 'invalid response' => [ |
||
316 | $responseMock, |
||
317 | new Result(false, 'I am a test'), |
||
318 | 0, |
||
319 | function (PHPUnit_Framework_MockObject_MockObject $responseValidatorMock) { |
||
320 | // Specifically setting expectations for the result of the response validator's "check" call |
||
321 | $responseValidatorMock->expects($this->once())->method('check') |
||
322 | ->willThrowException(new Exception('I am a test')); |
||
323 | }, |
||
328 |
This check looks for imports that have been defined, but are not used in the scope.