Passed
Pull Request — master (#40)
by Adam
05:51
created

DatabaseBackups::download()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Connector\ClientInterface;
6
use AcquiaCloudApi\Response\BackupsResponse;
7
use AcquiaCloudApi\Response\BackupResponse;
8
use AcquiaCloudApi\Response\OperationResponse;
9
use Psr\Http\Message\StreamInterface;
10
11
/**
12
 * Class DatabaseBackups
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 Psr\Http\Message\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