Passed
Push — master ( 7e5c00...1b1e9e )
by Adam
02:34
created

Variables   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 1
A delete() 0 4 1
A update() 0 11 1
A getAll() 0 6 1
A create() 0 11 1
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\OperationResponse;
6
use AcquiaCloudApi\Response\VariableResponse;
7
use AcquiaCloudApi\Response\VariablesResponse;
8
9
/**
10
 * Class Variables
11
 * @package AcquiaCloudApi\Endpoints
12
 */
13
class Variables extends CloudApiBase implements CloudApiInterface
14
{
15
16
    /**
17
     * Fetches all environment variables.
18
     *
19
     * @param string $environmentUuid
20
     * @return VariablesResponse
21
     */
22
    public function getAll($environmentUuid)
23
    {
24
        return new VariablesResponse(
25
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...nmentUuid.'/variables') can also be of type Psr\Http\Message\StreamInterface; however, parameter $variables 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
                "/environments/${environmentUuid}/variables"
28
            )
29
        );
30
    }
31
32
    /**
33
     * Returns details about an environment variable.
34
     *
35
     * @param string $environmentUuid
36
     * @param string $name
37
     * @return VariableResponse
38
     */
39
    public function get($environmentUuid, $name)
40
    {
41
        return new VariableResponse(
42
            $this->client->request(
43
                'get',
44
                "/environments/${environmentUuid}/variables/${name}"
45
            )
46
        );
47
    }
48
49
    /**
50
     * Adds an environment variable.
51
     *
52
     * @param string $environmentUuid
53
     * @param string $name
54
     * @param string $value
55
     * @return OperationResponse
56
     */
57
    public function create($environmentUuid, $name, $value)
58
    {
59
        $options = [
60
            'form_params' => [
61
                'name' => $name,
62
                'value' => $value,
63
            ],
64
        ];
65
66
        return new OperationResponse(
67
            $this->client->request('post', "/environments/${environmentUuid}/variables", $options)
68
        );
69
    }
70
71
    /**
72
     * Updates an environment variable.
73
     *
74
     * @param string $environmentUuid
75
     * @param string $name
76
     * @param string $value
77
     * @return OperationResponse
78
     */
79
    public function update($environmentUuid, $name, $value)
80
    {
81
        $options = [
82
            'form_params' => [
83
                'name' => $name,
84
                'value' => $value,
85
            ],
86
        ];
87
88
        return new OperationResponse(
89
            $this->client->request('put', "/environments/${environmentUuid}/variables/${name}", $options)
90
        );
91
    }
92
93
    /**
94
     * Deletes an environment variable.
95
     *
96
     * @param string $environmentUuid
97
     * @param string $name
98
     * @return OperationResponse
99
     */
100
    public function delete($environmentUuid, $name)
101
    {
102
        return new OperationResponse(
103
            $this->client->request('delete', "/environments/${environmentUuid}/variables/${name}")
104
        );
105
    }
106
}
107