GoogleCloudTranslator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 37
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setSource() 0 6 1
A setTarget() 0 6 1
A translate() 0 9 1
1
<?php
2
3
namespace Ben182\AutoTranslate\Translators;
4
5
use Google\Cloud\Translate\TranslateClient;
6
7
class GoogleCloudTranslator implements TranslatorInterface
8
{
9
    protected $translator;
10
    protected $source;
11
    protected $target;
12
13
    public function __construct()
14
    {
15
        $this->translator = new TranslateClient([
16
            'key' => config('auto-translate.google_cloud_translator.api_key'),
17
        ]);
18
    }
19
20
    public function setSource(string $source)
21
    {
22
        $this->source = $source;
23
24
        return $this;
25
    }
26
27
    public function setTarget(string $target)
28
    {
29
        $this->target = $target;
30
31
        return $this;
32
    }
33
34
    public function translate(string $string) : string
35
    {
36
        $result = $this->translator->translate($string, [
37
            'source' => $this->source,
38
            'target' => $this->target,
39
        ]);
40
41
        return $result['text'];
42
    }
43
}
44