Passed
Pull Request — master (#34)
by Adam
03:20
created

Crons::disable()   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 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Connector\ClientInterface;
6
use AcquiaCloudApi\Response\CronsResponse;
7
use AcquiaCloudApi\Response\CronResponse;
8
use AcquiaCloudApi\Response\OperationResponse;
9
10
/**
11
 * Class Client
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class Crons 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
     * Show all cron tasks for an environment.
32
     *
33
     * @param string $environmentUuid The environment ID
34
     * @return CronsResponse
35
     */
36
    public function getAll($environmentUuid)
37
    {
38
        return new CronsResponse(
39
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...vironmentUuid.'/crons') can also be of type Psr\Http\Message\StreamInterface and object; however, parameter $crons 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}/crons"
42
            )
43
        );
44
    }
45
46
    /**
47
     * Get information about a cron task.
48
     *
49
     * @param string $environmentUuid The environment ID
50
     * @param int    $cronId
51
     * @return CronResponse
52
     */
53
    public function get($environmentUuid, $cronId)
54
    {
55
        return new CronResponse(
56
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...Uuid.'/crons/'.$cronId) can also be of type array; however, parameter $cron 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}/crons/${cronId}"
59
            )
60
        );
61
    }
62
63
    /**
64
     * Add a cron task.
65
     *
66
     * @param string $environmentUuid
67
     * @param string $command
68
     * @param string $frequency
69
     * @param string $label
70
     * @return OperationResponse
71
     */
72
    public function create($environmentUuid, $command, $frequency, $label, $serverId = null)
73
    {
74
75
        $options = [
76
            'form_params' => [
77
                'command' => $command,
78
                'frequency' => $frequency,
79
                'label' => $label,
80
                'server_id' => $serverId
81
            ],
82
        ];
83
84
        return new OperationResponse(
85
            $this->client->request('post', "/environments/${environmentUuid}/crons", $options)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...uid.'/crons', $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

85
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${environmentUuid}/crons", $options)
Loading history...
86
        );
87
    }
88
89
    /**
90
     * Update a cron task.
91
     *
92
     * @param string $environmentUuid
93
     * @param string $command
94
     * @param string $frequency
95
     * @param string $label
96
     * @return OperationResponse
97
     */
98
    public function update($environmentUuid, $cronId, $command, $frequency, $label, $serverId = null)
99
    {
100
101
        $options = [
102
            'form_params' => [
103
                'command' => $command,
104
                'frequency' => $frequency,
105
                'label' => $label,
106
                'server_id' => $serverId
107
            ],
108
        ];
109
110
        return new OperationResponse(
111
            $this->client->request('post', "/environments/${environmentUuid}/crons/${cronId}", $options)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...ns/'.$cronId, $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

111
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${environmentUuid}/crons/${cronId}", $options)
Loading history...
112
        );
113
    }
114
115
    /**
116
     * Delete a cron task.
117
     *
118
     * @param string $environmentUuid
119
     * @param int    $cronId
120
     * @return OperationResponse
121
     */
122
    public function delete($environmentUuid, $cronId)
123
    {
124
        return new OperationResponse(
125
            $this->client->request('delete', "/environments/${environmentUuid}/crons/${cronId}")
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...Uuid.'/crons/'.$cronId) 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

125
            /** @scrutinizer ignore-type */ $this->client->request('delete', "/environments/${environmentUuid}/crons/${cronId}")
Loading history...
126
        );
127
    }
128
129
    /**
130
     * Disable a cron task.
131
     *
132
     * @param string $environmentUuid
133
     * @param int    $cronId
134
     * @return OperationResponse
135
     */
136
    public function disable($environmentUuid, $cronId)
137
    {
138
        return new OperationResponse(
139
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...nId.'/actions/disable') 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

139
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
140
                'post',
141
                "/environments/${environmentUuid}/crons/${cronId}/actions/disable"
142
            )
143
        );
144
    }
145
146
    /**
147
     * Enable a cron task.
148
     *
149
     * @param string $environmentUuid
150
     * @param int    $cronId
151
     * @return OperationResponse
152
     */
153
    public function enable($environmentUuid, $cronId)
154
    {
155
        return new OperationResponse(
156
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...onId.'/actions/enable') 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

156
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
157
                'post',
158
                "/environments/${environmentUuid}/crons/${cronId}/actions/enable"
159
            )
160
        );
161
    }
162
}
163