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

Crons::get()   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 Crons
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class Crons extends CloudApiBase implements CloudApiInterface
15
{
16
17
    /**
18
     * Show all cron tasks for an environment.
19
     *
20
     * @param string $environmentUuid The environment ID
21
     * @return CronsResponse
22
     */
23
    public function getAll($environmentUuid)
24
    {
25
        return new CronsResponse(
26
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...vironmentUuid.'/crons') can also be of type 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

26
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
27
                'get',
28
                "/environments/${environmentUuid}/crons"
29
            )
30
        );
31
    }
32
33
    /**
34
     * Get information about a cron task.
35
     *
36
     * @param string $environmentUuid The environment ID
37
     * @param int    $cronId
38
     * @return CronResponse
39
     */
40
    public function get($environmentUuid, $cronId)
41
    {
42
        return new CronResponse(
43
            $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

43
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
44
                'get',
45
                "/environments/${environmentUuid}/crons/${cronId}"
46
            )
47
        );
48
    }
49
50
    /**
51
     * Add a cron task.
52
     *
53
     * @param string $environmentUuid
54
     * @param string $command
55
     * @param string $frequency
56
     * @param string $label
57
     * @param string $serverId
58
     * @return OperationResponse
59
     */
60
    public function create($environmentUuid, $command, $frequency, $label, $serverId = null)
61
    {
62
63
        $options = [
64
            'form_params' => [
65
                'command' => $command,
66
                'frequency' => $frequency,
67
                'label' => $label,
68
                'server_id' => $serverId
69
            ],
70
        ];
71
72
        return new OperationResponse(
73
            $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

73
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${environmentUuid}/crons", $options)
Loading history...
74
        );
75
    }
76
77
    /**
78
     * Update a cron task.
79
     *
80
     * @param string $environmentUuid
81
     * @param string $cronId
82
     * @param string $command
83
     * @param string $frequency
84
     * @param string $label
85
     * @param string $serverId
86
     * @return OperationResponse
87
     */
88
    public function update($environmentUuid, $cronId, $command, $frequency, $label, $serverId = null)
89
    {
90
91
        $options = [
92
            'form_params' => [
93
                'command' => $command,
94
                'frequency' => $frequency,
95
                'label' => $label,
96
                'server_id' => $serverId
97
            ],
98
        ];
99
100
        return new OperationResponse(
101
            $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

101
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${environmentUuid}/crons/${cronId}", $options)
Loading history...
102
        );
103
    }
104
105
    /**
106
     * Delete a cron task.
107
     *
108
     * @param string $environmentUuid
109
     * @param int    $cronId
110
     * @return OperationResponse
111
     */
112
    public function delete($environmentUuid, $cronId)
113
    {
114
        return new OperationResponse(
115
            $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

115
            /** @scrutinizer ignore-type */ $this->client->request('delete', "/environments/${environmentUuid}/crons/${cronId}")
Loading history...
116
        );
117
    }
118
119
    /**
120
     * Disable a cron task.
121
     *
122
     * @param string $environmentUuid
123
     * @param int    $cronId
124
     * @return OperationResponse
125
     */
126
    public function disable($environmentUuid, $cronId)
127
    {
128
        return new OperationResponse(
129
            $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

129
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
130
                'post',
131
                "/environments/${environmentUuid}/crons/${cronId}/actions/disable"
132
            )
133
        );
134
    }
135
136
    /**
137
     * Enable a cron task.
138
     *
139
     * @param string $environmentUuid
140
     * @param int    $cronId
141
     * @return OperationResponse
142
     */
143
    public function enable($environmentUuid, $cronId)
144
    {
145
        return new OperationResponse(
146
            $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

146
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
147
                'post',
148
                "/environments/${environmentUuid}/crons/${cronId}/actions/enable"
149
            )
150
        );
151
    }
152
}
153