Completed
Push — master ( 56aaf5...cbecf1 )
by Aitor Riba
01:54
created

MymemoryTrans   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 44
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B main() 0 36 5
1
<?php
2
3
namespace Aitor24\Laralang\Builder;
4
5
class MymemoryTrans extends Translation
6
{
7
8
     /**
9
      * Get translation from mymemory API.
10
      */
11
     public function main()
12
     {
13
         $host = 'api.mymemory.translated.net';
14
15
         // Check if host is online.
16
         if ($this->checkHost($host)) {
17
18
             // Host online
19
             $urlString = urlencode($this->string);
20
             $url = "http://$host/get?q=$urlString&langpair=$this->from%7C$this->to";
21
             $json = file_get_contents($url);
22
             $data = json_decode($json);
23
24
             // Checking response status
25
             if ($data->responseStatus != 200) {
26
                 if ($this->debug == true) {
27
                     $details = $data->responseDetails;
28
                     if ($data->responseStatus == 403) {
29
                         $details = ($data->responseDetails);
30
                     }
31
                     $this->translation = "<font style='color:red;'>Error ".$data->responseStatus.': '.$details.'</font>';
32
                 }
33
34
                 return;
35
             }
36
37
38
             $transObtained = $data->responseData->translatedText;
39
40
             $this->translation = ucfirst(strtolower(trim($transObtained)));
41
42
             $this->checkSave();
43
44
             return;
45
         }
46
     }
47
48
}
49