Completed
Pull Request — master (#34)
by Adam
03:24
created

Code::deploy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
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 3
dl 0
loc 15
rs 9.9666
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Connector\ClientInterface;
6
use AcquiaCloudApi\Response\BranchesResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
9
/**
10
 * Class Client
11
 * @package AcquiaCloudApi\CloudApi
12
 */
13
class Code 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 code branches and tags in an application.
31
     *
32
     * @param string $applicationUuid
33
     * @return BranchesResponse
34
     */
35
    public function getAll($applicationUuid)
36
    {
37
        return new BranchesResponse(
38
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...pplicationUuid.'/code') can also be of type object; however, parameter $branches 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}/code"
41
            )
42
        );
43
    }
44
    
45
    /**
46
     * Deploys a code branch/tag to an environment.
47
     *
48
     * @param string $environmentUuid
49
     * @param string $branch
50
     * @return OperationResponse
51
     */
52
    public function switch($environmentUuid, $branch)
53
    {
54
55
        $options = [
56
            'form_params' => [
57
                'branch' => $branch,
58
            ],
59
        ];
60
61
        return new OperationResponse(
62
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...ions/switch', $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

62
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
63
                'post',
64
                "/environments/${environmentUuid}/code/actions/switch",
65
                $options
66
            )
67
        );
68
    }
69
70
    /**
71
     * Deploys code from one environment to another environment.
72
     *
73
     * @param string $environmentFromUuid
74
     * @param string $environmentToUuid
75
     * @param string $commitMessage
76
     */
77
    public function deploy($environmentFromUuid, $environmentToUuid, $commitMessage = null)
78
    {
79
80
        $options = [
81
            'form_params' => [
82
                'source' => $environmentFromUuid,
83
                'message' => $commitMessage,
84
            ],
85
        ];
86
87
        return new OperationResponse(
88
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...Uuid.'/code', $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

88
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
89
                'post',
90
                "/environments/${environmentToUuid}/code",
91
                $options
92
            )
93
        );
94
    }
95
}
96