Code::switch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 14
rs 9.9666
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\BranchesResponse;
6
use AcquiaCloudApi\Response\BranchResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
9
/**
10
 * Class Code
11
 *
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class Code extends CloudApiBase
15
{
16
    /**
17
     * Shows all code branches and tags in an application.
18
     *
19
     * @return BranchesResponse<BranchResponse>
20
     */
21
    public function getAll(string $applicationUuid): BranchesResponse
22
    {
23
        return new BranchesResponse(
24
            $this->client->request(
25
                'get',
26
                "/applications/$applicationUuid/code"
27
            )
28
        );
29
    }
30
31
    /**
32
     * Deploys a code branch/tag to an environment.
33
     */
34
    public function switch(string $environmentUuid, string $branch): OperationResponse
35
    {
36
37
        $options = [
38
            'json' => [
39
                'branch' => $branch,
40
            ],
41
        ];
42
43
        return new OperationResponse(
44
            $this->client->request(
45
                'post',
46
                "/environments/$environmentUuid/code/actions/switch",
47
                $options
48
            )
49
        );
50
    }
51
52
    /**
53
     * Deploys code from one environment to another environment.
54
     */
55
    public function deploy(
56
        string $environmentFromUuid,
57
        string $environmentToUuid,
58
        ?string $commitMessage = null
59
    ): OperationResponse {
60
61
        $options = [
62
            'json' => [
63
                'source' => $environmentFromUuid,
64
                'message' => $commitMessage,
65
            ],
66
        ];
67
68
        return new OperationResponse(
69
            $this->client->request(
70
                'post',
71
                "/environments/$environmentToUuid/code",
72
                $options
73
            )
74
        );
75
    }
76
}
77