Completed
Push — master ( c715fc...482a25 )
by Aitor Riba
01:56
created

MymemoryTrans   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 41
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Aitor24\Laralang\Builder;
4
5
class MymemoryTrans extends Translation
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
6
{
7
    /**
8
      * Get translation from mymemory API.
9
      */
10
     public function main()
11
     {
12
         $host = 'api.mymemory.translated.net';
13
14
         // Check if host is online.
15
         if ($this->checkHost($host)) {
16
17
             // Host online
18
             $urlString = urlencode($this->string);
19
             $urldata = file_get_contents("http://$host/get?q=$urlString&langpair=$this->from|$this->to");
20
             $data = json_decode($urldata, true);
21
22
             if ($data['responseStatus'] != 200) {
23
                 if ($this->debug == true) {
24
                     if ($data['responseStatus'] == 403) {
25
                         $details = ($data['responseDetails']);
26
                     } else {
27
                         $details = $data['responseDetails'];
28
                     }
29
                     $this->translation = "<font style='color:red;'>Error ".$data->responseStatus.': '.$details.'</font>';
30
                 }
31
                 return;
32
             }
33
34
<<<<<<< HEAD
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_SL
Loading history...
35
             $this->translation = $data['responseData']['translatedText'];
36
=======
37
             $transObtained = $data->responseData->translatedText;
38
39
             $this->translation = ucfirst(strtolower(trim($transObtained)));
40
>>>>>>> origin/master
41
42
             $this->checkSave();
43
44
             return;
45
         }
46
     }
47
}
48