Completed
Pull Request — master (#34)
by Adam
09:18
created

Crons   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
dl 0
loc 132
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A disable() 0 6 1
A delete() 0 4 1
A getAll() 0 6 1
A get() 0 6 1
A update() 0 14 1
A enable() 0 6 1
A create() 0 14 1
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
     * @return OperationResponse
58
     */
59
    public function create($environmentUuid, $command, $frequency, $label, $serverId = null)
60
    {
61
62
        $options = [
63
            'form_params' => [
64
                'command' => $command,
65
                'frequency' => $frequency,
66
                'label' => $label,
67
                'server_id' => $serverId
68
            ],
69
        ];
70
71
        return new OperationResponse(
72
            $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

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

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

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

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

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