Conditions | 2 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
19 | 4 | public function translate(array $strings): array |
|
20 | { |
||
21 | 4 | $guzzleClient = new Client(); |
|
22 | $options = [ |
||
23 | 'form_params' => [ |
||
24 | 4 | 'text' => implode(' | ', $strings), |
|
25 | 4 | 'from' => $this->from, |
|
26 | 4 | 'to' => $this->to, |
|
27 | ] |
||
28 | ]; |
||
29 | 4 | $request = $guzzleClient->request('POST', 'https://www.bing.com/ttranslate', $options); |
|
30 | |||
31 | 4 | $newStrings = []; |
|
32 | 4 | $response = json_decode((string) $request->getBody(), true); |
|
33 | 4 | if ($response['statusCode'] === 200) { |
|
34 | 4 | $newStrings = explode(' | ', $response['translationResponse']); |
|
35 | } |
||
36 | 4 | return array_combine($strings, $newStrings); |
|
37 | } |
||
39 |