Completed
Push — master ( 482a25...108ea4 )
by Aitor Riba
01:54
created

MymemoryTrans   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B main() 0 31 5
1
<?php
2
3
namespace Aitor24\Laralang\Builder;
4
5
class MymemoryTrans extends Translation
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
             $this->translation = $data['responseData']['translatedText'];
35
36
             $this->checkSave();
37
38
             return;
39
         }
40
     }
41
}
42