ListAllLanguagesRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A getBody() 0 3 1
A getQueryArguments() 0 3 1
A getURI() 0 3 1
A handleResponse() 0 16 3
1
<?php // Copyright ⓒ 2018 Magneds IP B.V. - All Rights Reserved
2
namespace Magneds\Lokalise\Language\Request;
3
4
use Magneds\Lokalise\Language\Entity\Language;
5
use Magneds\Lokalise\RequestInterface;
6
use Magneds\Lokalise\ResponseInfo;
7
use Psr\Http\Message\ResponseInterface;
8
9
class ListAllLanguagesRequest implements RequestInterface
10
{
11
    /**
12
     * Return the method to make this request in.
13
     *
14
     * @return string
15
     */
16
    public function getMethod()
17
    {
18
        return 'GET';
19
    }
20
21
    /**
22
     * This URI is appended to the route URL given to the Client object.
23
     *
24
     * @return string
25
     */
26
    public function getURI()
27
    {
28
        return 'language/listall';
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function getQueryArguments()
35
    {
36
        return [];
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getBody()
43
    {
44
        return [];
45
    }
46
47
    /**
48
     * @param ResponseInterface $response
49
     * @return mixed
50
     */
51
    public function handleResponse(ResponseInterface $response): ResponseInfo
52
    {
53
        $responseData = json_decode($response->getBody()->getContents(), true);
54
        $responseInfo = ResponseInfo::buildFromArray($responseData['response']);
55
56
        if ($responseInfo->getCode() !== 200) {
57
            return $responseInfo;
58
        }
59
60
        $languages = [];
61
        foreach ($responseData['languages'] as $language) {
62
            $languages[] = new Language($language['iso'], $language['name'], $language['rtl'] === "1");
63
        }
64
65
        $responseInfo->setActionData($languages);
66
        return $responseInfo;
67
    }
68
}
69