| Conditions | 6 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 47 | public function negotiate(Client $client): void |
||
| 48 | { |
||
| 49 | $method = $this->method; |
||
| 50 | if ($method === Client::AUTH_AUTO) { |
||
| 51 | $responseList = $client->emit(new CapabilityCommand($client->newTag())); |
||
| 52 | |||
| 53 | $capabilities = CapabilityCommandResponse::fromResponse($responseList->first()); |
||
| 54 | |||
| 55 | $responseList |
||
| 56 | ->last() |
||
| 57 | ->assertCompletion(CompletionResult::ok()) |
||
| 58 | ->assertTagged(); |
||
| 59 | |||
| 60 | $options = [ |
||
| 61 | 'AUTH=PLAIN' => Client::AUTH_PLAIN, |
||
| 62 | ]; |
||
| 63 | |||
| 64 | foreach ($options as $capability => $auth) { |
||
| 65 | if ($capabilities->isAdvertising($capability)) { |
||
| 66 | $method = $auth; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($method === Client::AUTH_AUTO) { |
||
| 71 | throw new ImapAuthenticationException( |
||
| 72 | 'IMAP server does not advertise one the supported AUTH methods (AUTH PLAIN)' |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | switch ($method) { |
||
| 78 | case Client::AUTH_PLAIN: |
||
| 79 | $tag = $client->newTag(); |
||
| 80 | $client |
||
| 81 | ->emit(new AuthPlainCommand($tag)) |
||
| 82 | ->first() |
||
| 83 | ->assertContinuation(); |
||
| 84 | |||
| 85 | $client |
||
| 86 | ->emit( |
||
| 87 | new AuthPlainCredentialsRequest( |
||
| 88 | $tag, |
||
| 89 | $this->username, |
||
| 90 | $this->password |
||
| 91 | ) |
||
| 92 | ) |
||
| 93 | ->last() |
||
| 94 | ->assertCompletion(CompletionResult::ok()) |
||
| 95 | ->assertTagged(); |
||
| 96 | break; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |