ListLanguagesRequest::getQueryArguments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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\Language\Entity\ProjectLanguage;
6
use Magneds\Lokalise\Project\Entity\ProjectID;
7
use Magneds\Lokalise\RequestInterface;
8
use Magneds\Lokalise\ResponseInfo;
9
use Psr\Http\Message\ResponseInterface;
10
11
class ListLanguagesRequest implements RequestInterface
12
{
13
    /**
14
     * @var ProjectID
15
     */
16
    protected $projectID;
17
18
    /**
19
     * ListLanguagesRequest constructor.
20
     * @param ProjectID $projectID
21
     */
22
    public function __construct(ProjectID $projectID)
23
    {
24
        $this->projectID = $projectID;
25
    }
26
27
    /**
28
     * Return the method to make this request in.
29
     *
30
     * @return string
31
     */
32
    public function getMethod()
33
    {
34
        return 'GET';
35
    }
36
37
    /**
38
     * This URI is appended to the route URL given to the Client object.
39
     *
40
     * @return string
41
     */
42
    public function getURI()
43
    {
44
        return 'language/list';
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getQueryArguments()
51
    {
52
        return [
53
            'id' => $this->projectID->getID(),
54
        ];
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getBody()
61
    {
62
        return [];
63
    }
64
65
    /**
66
     * @param ResponseInterface $response
67
     * @return mixed
68
     */
69
    public function handleResponse(ResponseInterface $response): ResponseInfo
70
    {
71
        $responseData = json_decode($response->getBody()->getContents(), true);
72
73
        $languages = [];
74
        foreach ($responseData['languages'] as $projectLanguage) {
75
            $languages[] = new ProjectLanguage(
76
                new Language($projectLanguage['iso'], $projectLanguage['name'], $projectLanguage['rtl'] === "1"),
77
                (int)$projectLanguage['words'],
78
                $projectLanguage['is_default'] === "1"
79
            );
80
        }
81
82
        return $languages;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $languages returns the type Magneds\Lokalise\Languag...ProjectLanguage[]|array which is incompatible with the type-hinted return Magneds\Lokalise\ResponseInfo.
Loading history...
83
    }
84
}
85