| Conditions | 7 |
| Paths | 22 |
| Total Lines | 58 |
| Code Lines | 32 |
| 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 |
||
| 80 | public function start( |
||
| 81 | AccountData $accountData, |
||
| 82 | DomainValidationData $domainValidation, |
||
| 83 | AuthorizationChallengeEnum $authChallenge, |
||
| 84 | bool $localTest = true |
||
| 85 | ): Response { |
||
| 86 | $this->client->logger('info', sprintf( |
||
| 87 | 'Start %s challenge for %s', |
||
| 88 | $authChallenge->value, |
||
| 89 | Arr::get($domainValidation->identifier, 'value', '') |
||
| 90 | )); |
||
| 91 | |||
| 92 | $type = $authChallenge === AuthorizationChallengeEnum::DNS ? 'dns' : 'file'; |
||
| 93 | $thumbprint = JsonWebKey::thumbprint(JsonWebKey::compute($this->getAccountPrivateKey())); |
||
| 94 | |||
| 95 | if (empty($domainValidation->{$type})) { |
||
| 96 | throw new DomainValidationException(sprintf('No %s challenge found for %s', $type, $domainValidation->identifier['value'])); |
||
| 97 | } |
||
| 98 | |||
| 99 | $keyAuthorization = $domainValidation->{$type}['token'].'.'.$thumbprint; |
||
| 100 | |||
| 101 | if ($localTest) { |
||
| 102 | if ($authChallenge === AuthorizationChallengeEnum::HTTP) { |
||
| 103 | LocalChallengeTest::http( |
||
| 104 | $domainValidation->identifier['value'], |
||
| 105 | $domainValidation->file['token'], |
||
| 106 | $keyAuthorization, |
||
| 107 | $this->client->getHttpClient() |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($authChallenge === AuthorizationChallengeEnum::DNS) { |
||
| 112 | LocalChallengeTest::dns( |
||
| 113 | $domainValidation->identifier['value'], |
||
| 114 | '_acme-challenge', |
||
| 115 | DnsDigest::make($domainValidation->{$type}['token'], $thumbprint), |
||
| 116 | ); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | $payload = [ |
||
| 121 | 'keyAuthorization' => $keyAuthorization, |
||
| 122 | ]; |
||
| 123 | |||
| 124 | $data = $this->createKeyId($accountData->url, $domainValidation->{$type}['url'], $payload); |
||
| 125 | |||
| 126 | $response = $this->client->getHttpClient()->post($domainValidation->{$type}['url'], $data); |
||
| 127 | |||
| 128 | if ($response->getHttpResponseCode() >= 400) { |
||
| 129 | $this->logResponse( |
||
| 130 | 'error', |
||
| 131 | $response->getBody()['detail'] ?? 'Unknown error', |
||
| 132 | $response, |
||
| 133 | ['payload' => $payload, 'data' => $data] |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | |||
| 137 | return $response; |
||
| 138 | } |
||
| 182 |