| Conditions | 7 |
| Paths | 7 |
| Total Lines | 51 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 66 | private function createResponse(array $response): AuthenticatorResponse |
||
| 67 | { |
||
| 68 | if (!array_key_exists('clientDataJSON', $response)) { |
||
| 69 | throw new \InvalidArgumentException(); |
||
| 70 | } |
||
| 71 | if (array_key_exists('attestationObject', $response)) { |
||
| 72 | $attestationObject = $this->attestationObjectLoader->load($response['attestationObject']); |
||
| 73 | |||
| 74 | return new AuthenticatorAttestationResponse( |
||
| 75 | CollectedClientData::createFormJson($response['clientDataJSON']), |
||
| 76 | $attestationObject |
||
| 77 | ); |
||
| 78 | } |
||
| 79 | if (array_key_exists('authenticatorData', $response) && array_key_exists('signature', $response)) { |
||
| 80 | $authData = Base64Url::decode($response['authenticatorData']); |
||
| 81 | |||
| 82 | $authDataStream = new StringStream($authData); |
||
| 83 | $rp_id_hash = $authDataStream->read(32); |
||
| 84 | $flags = $authDataStream->read(1); |
||
| 85 | $signCount = $authDataStream->read(4); |
||
| 86 | $signCount = unpack('N', $signCount)[1]; |
||
| 87 | |||
| 88 | if (\ord($flags) & self::FLAG_AT) { |
||
| 89 | $aaguid = $authDataStream->read(16); |
||
| 90 | $credentialLength = $authDataStream->read(2); |
||
| 91 | $credentialLength = unpack('n', $credentialLength)[1]; |
||
| 92 | $credentialId = $authDataStream->read($credentialLength); |
||
| 93 | $credentialPublicKey = $this->decoder->decode($authDataStream); |
||
| 94 | $attestedCredentialData = new AttestedCredentialData($aaguid, $credentialId, $credentialPublicKey); |
||
|
|
|||
| 95 | } else { |
||
| 96 | $attestedCredentialData = null; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (\ord($flags) & self::FLAG_ED) { |
||
| 100 | $extension = $this->decoder->decode($authDataStream); |
||
| 101 | } else { |
||
| 102 | $extension = null; |
||
| 103 | } |
||
| 104 | $authenticatorData = new AuthenticatorData( |
||
| 105 | $rp_id_hash, |
||
| 106 | $flags, |
||
| 107 | $signCount, |
||
| 108 | $attestedCredentialData, |
||
| 109 | $extension |
||
| 110 | ); |
||
| 111 | |||
| 112 | return new AuthenticatorAssertionResponse( |
||
| 113 | CollectedClientData::createFormJson($response['clientDataJSON']), |
||
| 114 | $authenticatorData, |
||
| 115 | Base64Url::decode($response['signature']), |
||
| 116 | $response['userHandle'] ?? null |
||
| 117 | ); |
||
| 121 |