Completed
Pull Request — master (#46)
by Adam
02:36
created

Databases::truncate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
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\DatabasesResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
9
/**
10
 * Class Databases
11
 * @package AcquiaCloudApi\CloudApi
12
 */
13
class Databases extends CloudApiBase implements CloudApiInterface
14
{
15
16
    /**
17
     * Shows all databases in an application.
18
     *
19
     * @param string $applicationUuid
20
     * @return DatabasesResponse
21
     */
22
    public function getAll($applicationUuid)
23
    {
24
        return new DatabasesResponse(
25
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...ationUuid.'/databases') can also be of type Psr\Http\Message\StreamInterface; however, parameter $databases 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

25
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
26
                'get',
27
                "/applications/${applicationUuid}/databases"
28
            )
29
        );
30
    }
31
32
    /**
33
     * Create a new database.
34
     *
35
     * @param string $applicationUuid
36
     * @param string $name
37
     * @return OperationResponse
38
     */
39
    public function create($applicationUuid, $name)
40
    {
41
        $options = [
42
            'form_params' => [
43
                'name' => $name,
44
            ],
45
        ];
46
47
        return new OperationResponse(
48
            $this->client->request('post', "/applications/${applicationUuid}/databases", $options)
49
        );
50
    }
51
52
    /**
53
     * Delete a database.
54
     *
55
     * @param string $applicationUuid
56
     * @param string $name
57
     * @return OperationResponse
58
     */
59
    public function delete($applicationUuid, $name)
60
    {
61
        return new OperationResponse(
62
            $this->client->request('delete', "/applications/${applicationUuid}/databases/${name}")
63
        );
64
    }
65
66
    /**
67
     * Erases (truncates) a database.
68
     *
69
     * This action will delete all tables of the database in ALL environments
70
     * within this application.
71
     *
72
     * @param string $applicationUuid
73
     * @param string $name
74
     * @return OperationResponse
75
     */
76
    public function truncate($applicationUuid, $name)
77
    {
78
        return new OperationResponse(
79
            $this->client->request(
80
                'post',
81
                "/applications/${applicationUuid}/databases/${name}/actions​/erase"
82
            )
83
        );
84
    }
85
86
    /**
87
     * Copies a database from an environment to an environment.
88
     *
89
     * @param string $environmentFromUuid
90
     * @param string $dbName
91
     * @param string $environmentToUuid
92
     * @return OperationResponse
93
     */
94
    public function copy($environmentFromUuid, $dbName, $environmentToUuid)
95
    {
96
        $options = [
97
            'form_params' => [
98
                'name' => $dbName,
99
                'source' => $environmentFromUuid,
100
            ],
101
        ];
102
103
        return new OperationResponse(
104
            $this->client->request('post', "/environments/${environmentToUuid}/databases", $options)
105
        );
106
    }
107
}
108