| Conditions | 11 |
| Paths | 8 |
| Total Lines | 65 |
| Code Lines | 33 |
| Lines | 17 |
| Ratio | 26.15 % |
| 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 |
||
| 143 | public function mymemoryTrans() |
||
| 144 | { |
||
| 145 | // Check if it can be translated from online sources. |
||
| 146 | |||
| 147 | $host = 'api.mymemory.translated.net'; |
||
| 148 | if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) { |
||
| 149 | |||
| 150 | // Host online |
||
| 151 | $urlString = urlencode($this->string); |
||
| 152 | $url = "http://$host/get?q=$urlString&langpair=$this->from%7C$this->to"; |
||
| 153 | $json = file_get_contents($url); |
||
| 154 | $data = json_decode($json); |
||
| 155 | |||
| 156 | // Checking response status |
||
| 157 | |||
| 158 | if ($data->responseStatus != 200) { |
||
| 159 | if ($this->debug == true) { |
||
| 160 | $details = $data->responseDetails; |
||
| 161 | if ($data->responseStatus == 403) { |
||
| 162 | $details =($data->responseDetails); |
||
| 163 | } |
||
| 164 | $this->translation = "<font style='color:red;'>Error ".$data->responseStatus.": ".$details."</font>"; |
||
| 165 | } |
||
| 166 | |||
| 167 | return; |
||
| 168 | } |
||
| 169 | |||
| 170 | $transObtained = $data->responseData->translatedText; |
||
| 171 | |||
| 172 | $this->translation = ucfirst(strtolower(trim($transObtained))); |
||
| 173 | |||
| 174 | |||
| 175 | // Checking debug setting to determinate how to output translation |
||
| 176 | |||
| 177 | View Code Duplication | if ($this->debug == true) { |
|
| 178 | $errors = ''; |
||
| 179 | $words = explode(' ', $transObtained); |
||
| 180 | foreach ($words as $word) { |
||
| 181 | if ($word != '') { |
||
| 182 | if ($word[0] == '*') { |
||
| 183 | $errors = $errors.substr($word, 1).', '; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | if ($errors == '') { |
||
| 189 | $this->translation = "<font style='color:#00CC00;'>".$this->translation."</font>"; |
||
| 190 | } else { |
||
| 191 | $this->translation = "<font style='color:orange;'>Unknoun words: ".substr($errors, 0, -2)."</font>"; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | fclose($socket); |
||
| 196 | return; |
||
| 197 | |||
| 198 | } else { |
||
| 199 | |||
| 200 | // host offline |
||
| 201 | |||
| 202 | if ($this->debug == true) { |
||
| 203 | $this->translation = "<font style='color:red;'>Mymeory host is down</font>"; |
||
| 204 | } |
||
| 205 | return; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 282 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.