Completed
Push — master ( 5a6804...6e73eb )
by Byron
03:25
created

Translate::getRequestMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace badams\MicrosoftTranslator\Methods;
4
5
use badams\MicrosoftTranslator\ApiMethodInterface;
6
7
/**
8
 * Class Translate
9
 * @package badams\MicrosoftTranslator\Methods
10
 */
11
class Translate implements ApiMethodInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $text;
17
18
    /**
19
     * @var string
20
     */
21
    protected $to;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $from;
27
28
    /**
29
     * Translate constructor.
30
     * @param $text
31
     * @param $to
32
     * @param null $from
33
     */
34 15
    public function __construct($text, $to, $from = null)
35
    {
36 15
        $this->text = $text;
37 15
        $this->to = $to;
38 15
        $this->from = $from;
39 15
    }
40
41 15
    public function getRequestMethod()
42
    {
43 15
        return 'GET';
44
    }
45
46
    /**
47
     * @return array
48
     */
49 15
    public function getRequestOptions()
50
    {
51
        return [
52
            'query' => [
53 15
                'text' => $this->text,
54 15
                'to' => $this->to,
55 15
                'from' => $this->from,
56
            ]
57 15
        ];
58
    }
59
60
    /**
61
     * @param \GuzzleHttp\Message\Response $response
62
     * @return string
63
     */
64 6
    public function processResponse(\GuzzleHttp\Message\Response $response)
65
    {
66 6
        $xml = (array)simplexml_load_string($response->getBody()->getContents());
67 6
        return (string)$xml[0];
68
    }
69
70
71
}