Passed
Pull Request — master (#34)
by Adam
03:20
created

Databases   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 85
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 4 1
A __construct() 0 3 1
A getAll() 0 6 1
A create() 0 10 1
A copy() 0 11 1
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 Client
11
 * @package AcquiaCloudApi\CloudApi
12
 */
13
class Databases implements CloudApi
14
{
15
16
    /** @var ClientInterface The API client. */
17
    protected $client;
18
19
    /**
20
     * Client constructor.
21
     *
22
     * @param ClientInterface $client
23
     */
24
    public function __construct(ClientInterface $client)
25
    {
26
        $this->client = $client;
27
    }
28
29
    /**
30
     * Shows all databases in an application.
31
     *
32
     * @param string $applicationUuid
33
     * @return DatabasesResponse
34
     */
35
    public function getAll($applicationUuid)
36
    {
37
        return new DatabasesResponse(
38
            $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 and object; 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

38
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
39
                'get',
40
                "/applications/${applicationUuid}/databases"
41
            )
42
        );
43
    }
44
45
    /**
46
     * Create a new database.
47
     *
48
     * @param string $applicationUuid
49
     * @param string $name
50
     * @return OperationResponse
51
     */
52
    public function create($applicationUuid, $name)
53
    {
54
        $options = [
55
            'form_params' => [
56
                'name' => $name,
57
            ],
58
        ];
59
60
        return new OperationResponse(
61
            $this->client->request('post', "/applications/${applicationUuid}/databases", $options)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...'/databases', $options) can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, 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

61
            /** @scrutinizer ignore-type */ $this->client->request('post', "/applications/${applicationUuid}/databases", $options)
Loading history...
62
        );
63
    }
64
65
    /**
66
     * Delete a database.
67
     *
68
     * @param string $applicationUuid
69
     * @param string $name
70
     * @return OperationResponse
71
     */
72
    public function delete($applicationUuid, $name)
73
    {
74
        return new OperationResponse(
75
            $this->client->request('delete', "/applications/${applicationUuid}/databases/${name}")
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...id.'/databases/'.$name) can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, 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

75
            /** @scrutinizer ignore-type */ $this->client->request('delete', "/applications/${applicationUuid}/databases/${name}")
Loading history...
76
        );
77
    }
78
79
    /**
80
     * Copies a database from an environment to an environment.
81
     *
82
     * @param string $environmentFromUuid
83
     * @param string $dbName
84
     * @param string $environmentToUuid
85
     * @return OperationResponse
86
     */
87
    public function copy($environmentFromUuid, $dbName, $environmentToUuid)
88
    {
89
        $options = [
90
            'form_params' => [
91
                'name' => $dbName,
92
                'source' => $environmentFromUuid,
93
            ],
94
        ];
95
96
        return new OperationResponse(
97
            $this->client->request('post', "/environments/${environmentToUuid}/databases", $options)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...'/databases', $options) can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, 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

97
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${environmentToUuid}/databases", $options)
Loading history...
98
        );
99
    }
100
}
101