| Conditions | 10 |
| Paths | 18 |
| Total Lines | 36 |
| 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 |
||
| 133 | protected function login($newPassword = false) |
||
| 134 | { |
||
| 135 | // send login command |
||
| 136 | $login = new LoginCommand(); |
||
| 137 | $login->setClientId($this->username); |
||
| 138 | $login->setPassword($this->password); |
||
| 139 | if ($newPassword) { |
||
| 140 | $login->setNewPassword($newPassword); |
||
| 141 | } |
||
| 142 | $login->setVersion('1.0'); |
||
| 143 | $login->setLanguage('en'); |
||
| 144 | |||
| 145 | if (!empty($this->services) && is_array($this->services)) { |
||
| 146 | foreach ($this->services as $urn) { |
||
| 147 | $login->addService($urn); |
||
| 148 | } |
||
| 149 | |||
| 150 | if (!empty($this->serviceExtensions) && is_array($this->serviceExtensions)) { |
||
| 151 | foreach ($this->serviceExtensions as $extension) { |
||
| 152 | $login->addServiceExtension($extension); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $response = $this->request($login); |
||
| 158 | unset($login); |
||
| 159 | |||
| 160 | // check if login was successful |
||
| 161 | if (!($response instanceof ResponseFrame)) { |
||
| 162 | throw new \Exception('there was a problem logging onto the EPP server'); |
||
| 163 | } elseif ($response->code() !== 1000) { |
||
| 164 | throw new \Exception($response->message(), $response->code()); |
||
| 165 | } |
||
| 166 | |||
| 167 | return $response; |
||
| 168 | } |
||
| 169 | } |
||
| 170 |