| Conditions | 17 |
| Paths | 10 |
| Total Lines | 76 |
| Code Lines | 43 |
| 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 __construct( |
||
| 86 | array $attestationData, |
||
| 87 | AuthenticatorData $authenticatorData |
||
| 88 | ) { |
||
| 89 | parent::__construct($attestationData, $authenticatorData); |
||
| 90 | |||
| 91 | // check packed data |
||
| 92 | $attestationStatement = $this->attestationData['attStmt']; |
||
| 93 | |||
| 94 | if ( |
||
| 95 | ! array_key_exists('ver', $attestationStatement) || |
||
| 96 | $attestationStatement['ver'] !== '2.0' |
||
| 97 | ) { |
||
| 98 | throw new WebauthnException(sprintf( |
||
| 99 | 'Invalid TPM version [%s]', |
||
| 100 | $attestationStatement['ver'] |
||
| 101 | )); |
||
| 102 | } |
||
| 103 | |||
| 104 | if ( |
||
| 105 | ! array_key_exists('alg', $attestationStatement) || |
||
| 106 | $this->getCoseAlgorithm($attestationStatement['alg']) === null |
||
| 107 | ) { |
||
| 108 | throw new WebauthnException(sprintf( |
||
| 109 | 'Unsupported algorithm provided, got [%d]', |
||
| 110 | $attestationStatement['alg'] |
||
| 111 | )); |
||
| 112 | } |
||
| 113 | |||
| 114 | if ( |
||
| 115 | ! array_key_exists('sig', $attestationStatement) || |
||
| 116 | ! $attestationStatement['sig'] instanceof ByteBuffer |
||
| 117 | ) { |
||
| 118 | throw new WebauthnException('No signature found'); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ( |
||
| 122 | ! array_key_exists('certInfo', $attestationStatement) || |
||
| 123 | ! $attestationStatement['certInfo'] instanceof ByteBuffer |
||
| 124 | ) { |
||
| 125 | throw new WebauthnException('No certificate information found'); |
||
| 126 | } |
||
| 127 | |||
| 128 | if ( |
||
| 129 | ! array_key_exists('pubArea', $attestationStatement) || |
||
| 130 | ! $attestationStatement['pubArea'] instanceof ByteBuffer |
||
| 131 | ) { |
||
| 132 | throw new WebauthnException('No public area information found'); |
||
| 133 | } |
||
| 134 | |||
| 135 | $this->algo = $attestationStatement['alg']; |
||
| 136 | $this->signature = $attestationStatement['sig']->getBinaryString(); |
||
| 137 | $this->certInfo = $attestationStatement['certInfo']; |
||
| 138 | $this->pubArea = $attestationStatement['pubArea']; |
||
| 139 | |||
| 140 | if ( |
||
| 141 | array_key_exists('x5c', $attestationStatement) && |
||
| 142 | is_array($attestationStatement['x5c']) && |
||
| 143 | count($attestationStatement['x5c']) > 0 |
||
| 144 | ) { |
||
| 145 | // The attestation certificate attestnCert MUST be the first element in the array |
||
| 146 | $attestCert = array_shift($attestationStatement['x5c']); |
||
| 147 | if (! $attestCert instanceof ByteBuffer) { |
||
| 148 | throw new WebauthnException('Invalid X5C certificate'); |
||
| 149 | } |
||
| 150 | |||
| 151 | $this->x5c = $attestCert->getBinaryString(); |
||
| 152 | |||
| 153 | // Certificate chains |
||
| 154 | foreach ($attestationStatement['x5c'] as $chain) { |
||
| 155 | if ($chain instanceof ByteBuffer) { |
||
| 156 | $this->x5cChain[] = $chain->getBinaryString(); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } else { |
||
| 160 | throw new WebauthnException('Invalid X5C certificate'); |
||
| 161 | } |
||
| 289 |