Test Failed
Pull Request — master (#34)
by Adam
03:36
created

Domains::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Connector\ClientInterface;
6
use AcquiaCloudApi\Response\DomainsResponse;
7
use AcquiaCloudApi\Response\DomainResponse;
8
use AcquiaCloudApi\Response\OperationResponse;
9
10
/**
11
 * Class Client
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class Domains implements CloudApi
15
{
16
17
    /** @var ClientInterface The API client. */
18
    protected $client;
19
20
    /**
21
     * Client constructor.
22
     *
23
     * @param ClientInterface $client
24
     */
25
    public function __construct(ClientInterface $client)
26
    {
27
        $this->client = $client;
28
    }
29
30
    /**
31
     * Shows all domains on an environment.
32
     *
33
     * @param string $environmentUuid
34
     * @return DomainsResponse
35
     */
36
    public function getAll($environmentUuid)
37
    {
38
        return new DomainsResponse(
39
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...ronmentUuid.'/domains') can also be of type object; however, parameter $domains 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

39
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
40
                'get',
41
                "/environments/${environmentUuid}/domains"
42
            )
43
        );
44
    }
45
46
    /**
47
     * Return details about a domain.
48
     *
49
     * @param string $environmentUuid
50
     * @param string $domain
51
     * @return DomainResponse
52
     */
53
    public function get($environmentUuid, $domain)
54
    {
55
        return new DomainResponse(
56
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...id.'/domains/'.$domain) can also be of type array; however, parameter $domain 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

56
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
57
                'get',
58
                "/environments/${environmentUuid}/domains/${domain}"
59
            )
60
        );
61
    }
62
63
    /**
64
     * Adds a domain to an environment.
65
     *
66
     * @param string $environmentUuid
67
     * @param string $hostname
68
     * @return OperationResponse
69
     */
70
    public function create($environmentUuid, $hostname)
71
    {
72
73
        $options = [
74
            'form_params' => [
75
                'hostname' => $hostname,
76
            ],
77
        ];
78
79
        return new OperationResponse(
80
            $this->client->request('post', "/environments/${environmentUuid}/domains", $options)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...d.'/domains', $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

80
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${environmentUuid}/domains", $options)
Loading history...
81
        );
82
    }
83
84
    /**
85
     * Deletes a domain from an environment.
86
     *
87
     * @param string $environmentUuid
88
     * @param string $domain
89
     * @return OperationResponse
90
     */
91
    public function delete($environmentUuid, $domain)
92
    {
93
        return new OperationResponse(
94
            $this->client->request('delete', "/environments/${environmentUuid}/domains/${domain}")
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...id.'/domains/'.$domain) 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

94
            /** @scrutinizer ignore-type */ $this->client->request('delete', "/environments/${environmentUuid}/domains/${domain}")
Loading history...
95
        );
96
    }
97
98
    /**
99
     * Purges varnish for selected domains in an environment.
100
     *
101
     * @param string $environmentUuid
102
     * @param array  $domains
103
     * @return OperationResponse
104
     */
105
    public function purge($environmentUuid, array $domains)
106
    {
107
108
        $options = [
109
            'form_params' => [
110
                'domains' => $domains,
111
            ],
112
        ];
113
114
        return new OperationResponse(
115
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...ear-varnish', $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

115
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
116
                'post',
117
                "/environments/${environmentUuid}/domains/actions/clear-varnish",
118
                $options
119
            )
120
        );
121
    }
122
}
123