SnapshotRequest::getBody()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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