| Conditions | 11 |
| Paths | 32 |
| Total Lines | 50 |
| Code Lines | 32 |
| 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 |
||
| 61 | public function createProcess( |
||
| 62 | array $challenges, |
||
| 63 | int $maxNFailedAttempts = 3, |
||
| 64 | ?string $username = null, |
||
| 65 | array $additionalData = [] |
||
| 66 | ): IAuthenticationProcess { |
||
| 67 | $dataArray = array_merge($additionalData, [ |
||
| 68 | 'used_u2f_key_public_keys' => new ArrayObject([], Scalar::_STR), |
||
|
|
|||
| 69 | 'challenges' => new ArrayObject($challenges, Scalar::_STR), |
||
| 70 | 'max_n_failed_attempts' => new IntegerObject($maxNFailedAttempts), |
||
| 71 | 'n_failed_attempts' => new IntegerObject(0), |
||
| 72 | 'persist_operations' => new ArrayObject([], PersistOperation::class), |
||
| 73 | 'status' => new Status(Status::ONGOING), |
||
| 74 | 'new_u2f_registrations' => new ArrayObject([], IU2fRegistration::class), |
||
| 75 | 'n_u2f_registrations' => new IntegerObject(0), |
||
| 76 | ]); |
||
| 77 | if (null !== $username) { |
||
| 78 | $dataArray['username'] = new StringObject($username); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ( |
||
| 82 | !isset($additionalData['u2f_registrations']) && |
||
| 83 | null !== $username |
||
| 84 | ) { |
||
| 85 | $dataArray['u2f_registrations'] = $this->appConfig->getU2fRegistrations($username); |
||
| 86 | } elseif ( |
||
| 87 | !isset($additionalData['u2f_registrations']) && |
||
| 88 | null === $username |
||
| 89 | ) { |
||
| 90 | $dataArray['u2f_registrations'] = []; |
||
| 91 | } elseif (isset($additionalData['u2f_registrations'])) { |
||
| 92 | $dataArray['u2f_registrations'] = $additionalData['u2f_registrations']; |
||
| 93 | } |
||
| 94 | |||
| 95 | if (isset($additionalData['used_u2f_key_public_keys'])) { |
||
| 96 | if (!is_array($additionalData['used_u2f_key_public_keys'])) { |
||
| 97 | throw new InvalidArgumentException('used_u2f_key_public_keys'); |
||
| 98 | } |
||
| 99 | foreach ($additionalData['used_u2f_key_public_keys'] as $pb) { |
||
| 100 | if (!is_string($pb)) { |
||
| 101 | throw new InvalidArgumentException('Public key must be string'); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | $data['used_u2f_key_public_keys'] = $additionalData['used_u2f_key_public_keys']; |
||
| 105 | } else { |
||
| 106 | $data['used_u2f_key_public_keys'] = []; |
||
| 107 | } |
||
| 108 | $typedMap = new TypedMap($dataArray); |
||
| 109 | |||
| 110 | return new AuthenticationProcess($typedMap); |
||
| 111 | } |
||
| 113 |