Passed
Push — master ( fbde60...b41207 )
by Adam
02:22
created

DatabaseBackups::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\BackupsResponse;
6
use AcquiaCloudApi\Response\BackupResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
use Psr\Http\Message\StreamInterface;
9
10
/**
11
 * Class DatabaseBackups
12
 *
13
 * @package AcquiaCloudApi\CloudApi
14
 */
15
class DatabaseBackups extends CloudApiBase implements CloudApiInterface
16
{
17
18
    /**
19
     * Backup a database.
20
     *
21
     * @param  string $environmentUuid
22
     * @param  string $dbName
23
     * @return OperationResponse
24
     */
25
    public function create($environmentUuid, $dbName)
26
    {
27
        return new OperationResponse(
28
            $this->client->request(
29
                'post',
30
                "/environments/${environmentUuid}/databases/${dbName}/backups"
31
            )
32
        );
33
    }
34
35
    /**
36
     * Shows all database backups in an environment.
37
     *
38
     * @param  string $environmentUuid
39
     * @param  string $dbName
40
     * @return BackupsResponse
41
     */
42
    public function getAll($environmentUuid, $dbName)
43
    {
44
        return new BackupsResponse(
45
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...s/'.$dbName.'/backups') can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $backups of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
46
                'get',
47
                "/environments/${environmentUuid}/databases/${dbName}/backups"
48
            )
49
        );
50
    }
51
52
    /**
53
     * Gets information about a database backup.
54
     *
55
     * @param  string $environmentUuid
56
     * @param  string $dbName
57
     * @param  int    $backupId
58
     * @return BackupResponse
59
     */
60
    public function get($environmentUuid, $dbName, $backupId)
61
    {
62
        return new BackupResponse(
63
            $this->client->request(
64
                'get',
65
                "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}"
66
            )
67
        );
68
    }
69
70
    /**
71
     * Restores a database backup to a database in an environment.
72
     *
73
     * @param  string $environmentUuid
74
     * @param  string $dbName
75
     * @param  int    $backupId
76
     * @return OperationResponse
77
     */
78
    public function restore($environmentUuid, $dbName, $backupId)
79
    {
80
        return new OperationResponse(
81
            $this->client->request(
82
                'post',
83
                "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}/actions/restore"
84
            )
85
        );
86
    }
87
88
    /**
89
     * Downloads a database backup.
90
     *
91
     * @param  string $environmentUuid
92
     * @param  string $dbName
93
     * @param  int    $backupId
94
     * @return StreamInterface
95
     */
96
    public function download($environmentUuid, $dbName, $backupId)
97
    {
98
        return $this->client->request(
99
            'get',
100
            "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}/actions/download"
101
        );
102
    }
103
104
    /**
105
     * Deletes a database backup.
106
     *
107
     * @param  string $environmentUuid
108
     * @param  string $dbName
109
     * @param  int    $backupId
110
     * @return OperationResponse
111
     */
112
    public function delete($environmentUuid, $dbName, $backupId)
113
    {
114
        return new OperationResponse(
115
            $this->client->request(
116
                'delete',
117
                "/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}"
118
            )
119
        );
120
    }
121
}
122