ListProjectsRequest::getURI()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php // Copyright ⓒ 2018 Magneds IP B.V. - All Rights Reserved
2
namespace Magneds\Lokalise\Project\Request;
3
4
use DateTime;
5
use DateTimeZone;
6
use Magneds\Lokalise\Project\Entity\Project;
7
use Magneds\Lokalise\Project\Entity\ProjectID;
8
use Magneds\Lokalise\RequestInterface;
9
use Magneds\Lokalise\ResponseInfo;
10
use Psr\Http\Message\ResponseInterface;
11
12
class ListProjectsRequest implements RequestInterface
13
{
14
    /**
15
     * Return the method to make this request in.
16
     *
17
     * @return string
18
     */
19
    public function getMethod()
20
    {
21
        return 'GET';
22
    }
23
24
    /**
25
     * This URI is appended to the route URL given to the Client object.
26
     *
27
     * @return string
28
     */
29
    public function getURI()
30
    {
31
        return 'project/list';
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    public function getQueryArguments()
38
    {
39
        return [];
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    public function getBody()
46
    {
47
        return [];
48
    }
49
50
    /**
51
     * @param ResponseInterface $response
52
     * @return ResponseInfo
53
     */
54
    public function handleResponse(ResponseInterface $response): ResponseInfo
55
    {
56
        $responseData = json_decode($response->getBody()->getContents(), true);
57
        $responseInfo = ResponseInfo::buildFromArray($responseData['response']);
58
59
        if ($responseInfo->getCode() !== 200) {
60
            return $responseInfo;
61
        }
62
63
        $projects  = [];
64
        foreach ($responseData['projects'] as $project) {
65
            $projects[] = Project::buildFromArray($project);
66
        }
67
68
        // Add it to the response object.
69
        $responseInfo->setActionData($projects);
70
71
        return $responseInfo;
72
    }
73
}
74