CodebaseEnvironments   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 41
c 1
b 0
f 0
dl 0
loc 118
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getById() 0 6 1
A update() 0 13 1
A disassociatePrivateNetwork() 0 6 1
A associatePrivateNetwork() 0 13 1
A getByPrivateNetwork() 0 6 1
A getBySite() 0 6 1
A get() 0 6 1
A getAll() 0 6 1
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\CodebaseEnvironmentResponse;
6
use AcquiaCloudApi\Response\CodebaseEnvironmentsResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
9
/**
10
 * Class CodebaseEnvironments
11
 *
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class CodebaseEnvironments extends CloudApiBase
15
{
16
    /**
17
     * Returns a list of environments for a codebase.
18
     */
19
    public function getAll(string $codebaseId): CodebaseEnvironmentsResponse
20
    {
21
        return new CodebaseEnvironmentsResponse(
22
            $this->client->request(
23
                'get',
24
                "/codebases/$codebaseId/environments"
25
            )
26
        );
27
    }
28
29
    /**
30
     * Returns information about a specific environment for a codebase.
31
     */
32
    public function get(string $codebaseId, string $environmentId): CodebaseEnvironmentResponse
33
    {
34
        return new CodebaseEnvironmentResponse(
35
            $this->client->request(
36
                'get',
37
                "/codebases/$codebaseId/environments/$environmentId"
38
            )
39
        );
40
    }
41
42
    /**
43
     * Returns information about a specific environment by ID.
44
     */
45
    public function getById(string $environmentId): CodebaseEnvironmentResponse
46
    {
47
        return new CodebaseEnvironmentResponse(
48
            $this->client->request(
49
                'get',
50
                "/v3/environments/$environmentId"
51
            )
52
        );
53
    }
54
55
    /**
56
     * Updates the properties for an environment.
57
     *
58
     * @param array<string, mixed> $properties
59
     */
60
    public function update(string $environmentId, array $properties): OperationResponse
61
    {
62
        $options = [
63
            'json' => [
64
                'properties' => $properties
65
            ],
66
        ];
67
68
        return new OperationResponse(
69
            $this->client->request(
70
                'put',
71
                "/v3/environments/$environmentId",
72
                $options
73
            )
74
        );
75
    }
76
77
    /**
78
     * Associates an environment with a private network.
79
     */
80
    public function associatePrivateNetwork(string $environmentId, string $privateNetworkId): OperationResponse
81
    {
82
        $options = [
83
            'json' => [
84
                'private_network_id' => $privateNetworkId
85
            ],
86
        ];
87
88
        return new OperationResponse(
89
            $this->client->request(
90
                'put',
91
                "/v3/environments/$environmentId/private-network",
92
                $options
93
            )
94
        );
95
    }
96
97
    /**
98
     * Disassociates an environment from a private network.
99
     */
100
    public function disassociatePrivateNetwork(string $environmentId): OperationResponse
101
    {
102
        return new OperationResponse(
103
            $this->client->request(
104
                'delete',
105
                "/v3/environments/$environmentId/private-network"
106
            )
107
        );
108
    }
109
110
    /**
111
     * Gets environments associated with a private network.
112
     */
113
    public function getByPrivateNetwork(string $privateNetworkId): CodebaseEnvironmentsResponse
114
    {
115
        return new CodebaseEnvironmentsResponse(
116
            $this->client->request(
117
                'get',
118
                "/v3/private-networks/$privateNetworkId/environments"
119
            )
120
        );
121
    }
122
123
    /**
124
     * Gets environments associated with a site.
125
     */
126
    public function getBySite(string $siteId): CodebaseEnvironmentsResponse
127
    {
128
        return new CodebaseEnvironmentsResponse(
129
            $this->client->request(
130
                'get',
131
                "/sites/$siteId/environments"
132
            )
133
        );
134
    }
135
}
136