| Conditions | 7 |
| Paths | 11 |
| Total Lines | 56 |
| Code Lines | 33 |
| Lines | 25 |
| Ratio | 44.64 % |
| Tests | 0 |
| CRAP Score | 56 |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 46 | public function connect() |
||
| 47 | { |
||
| 48 | $serverConfig = $this->getConfiguration(); |
||
| 49 | $this->sftp = new SFTP($serverConfig->getHost(), $serverConfig->getPort(), 3600); |
||
| 50 | |||
| 51 | switch ($serverConfig->getAuthenticationMethod()) { |
||
| 52 | case Configuration::AUTH_BY_PASSWORD: |
||
|
|
|||
| 53 | |||
| 54 | $result = $this->sftp->login($serverConfig->getUser(), $serverConfig->getPassword()); |
||
| 55 | |||
| 56 | break; |
||
| 57 | |||
| 58 | View Code Duplication | case Configuration::AUTH_BY_IDENTITY_FILE: |
|
| 59 | |||
| 60 | $key = new RSA(); |
||
| 61 | $key->setPassword($serverConfig->getPassPhrase()); |
||
| 62 | $key->loadKey(file_get_contents($serverConfig->getPrivateKey())); |
||
| 63 | |||
| 64 | $result = $this->sftp->login($serverConfig->getUser(), $key); |
||
| 65 | |||
| 66 | break; |
||
| 67 | |||
| 68 | View Code Duplication | case Configuration::AUTH_BY_PEM_FILE: |
|
| 69 | |||
| 70 | $key = new RSA(); |
||
| 71 | $key->loadKey(file_get_contents($serverConfig->getPemFile())); |
||
| 72 | $result = $this->sftp->login($serverConfig->getUser(), $key); |
||
| 73 | |||
| 74 | break; |
||
| 75 | |||
| 76 | case Configuration::AUTH_BY_AGENT: |
||
| 77 | |||
| 78 | $key = new Agent(); |
||
| 79 | $key->startSSHForwarding(null); |
||
| 80 | $result = $this->sftp->login($serverConfig->getUser(), $key); |
||
| 81 | |||
| 82 | break; |
||
| 83 | |||
| 84 | View Code Duplication | case Configuration::AUTH_BY_IDENTITY_FILE_AND_PASSWORD: |
|
|
2 ignored issues
–
show
|
|||
| 85 | |||
| 86 | $key = new RSA(); |
||
| 87 | $key->setPassword($serverConfig->getPassPhrase()); |
||
| 88 | $key->loadKey(file_get_contents($serverConfig->getPrivateKey())); |
||
| 89 | |||
| 90 | $result = $this->sftp->login($serverConfig->getUser(), $key, $serverConfig->getPassword()); |
||
| 91 | |||
| 92 | break; |
||
| 93 | |||
| 94 | default: |
||
| 95 | throw new RuntimeException('You need to specify authentication method.'); |
||
| 96 | } |
||
| 97 | |||
| 98 | if (!$result) { |
||
| 99 | throw new RuntimeException('Unable to login with the provided credentials.'); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 170 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.