Pages::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Pages extends Resource
6
{
7
    /**
8
     * Create a new page.
9
     *
10
     * @param array $params Optional Parameters.
11
     * @return \SevenShores\Hubspot\Http\Response
12
     */
13
    function create($params)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
    {
15
        $endpoint = 'https://api.hubapi.com/content/api/v2/pages';
16
17
        $options['json'] = $params;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
18
19
        return $this->client->request('post', $endpoint, $options);
20
    }
21
22
    /**
23
     * Get all pages.
24
     *
25
     * @param array $params Optional parameters.
26
     * @return \SevenShores\Hubspot\Http\Response
27
     */
28
    function all($params = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
    {
30
        $endpoint = "https://api.hubapi.com/content/api/v2/pages";
31
32
        $queryString = build_query_string($params);
33
34
        return $this->client->request('get', $endpoint, [], $queryString);
35
    }
36
37
    /**
38
     * Update a page.
39
     *
40
     * @param int   $page_id The page id.
41
     * @param array $params  The page fields to update.
42
     * @return \SevenShores\Hubspot\Http\Response
43
     */
44
    function update($page_id, $params)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
    {
46
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}";
47
48
        $options['json'] = $params;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
49
50
        return $this->client->request('put', $endpoint, $options);
51
    }
52
53
    /**
54
     * Delete a page.
55
     *
56
     * @param int $page_id
57
     * @return \SevenShores\Hubspot\Http\Response
58
     */
59
    function delete($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
60
    {
61
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}";
62
63
        return $this->client->request('delete', $endpoint);
64
    }
65
66
    /**
67
     * Get a specific page.
68
     *
69
     * @param int $page_id
70
     * @return \SevenShores\Hubspot\Http\Response
71
     */
72
    function getById($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
    {
74
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}";
75
76
        return $this->client->request('get', $endpoint);
77
    }
78
79
    /**
80
     * Updates the auto-save buffer.
81
     *
82
     * @param in $page_id The page ID
83
     * @return \SevenShores\Hubspot\Http\Response
84
     */
85
    function updateAutoSaveBuffer($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
86
    {
87
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/buffer";
88
89
        return $this->client->request('put', $endpoint);
90
    }
91
92
    /**
93
     * Gets the current contents of the auto-save buffer.
94
     *
95
     * @param int $page_id The page ID
96
     * @return \SevenShores\Hubspot\Http\Response
97
     */
98
    function getAutoSaveBufferContents($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
99
    {
100
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/buffer";
101
102
        return $this->client->request('get', $endpoint);
103
    }
104
105
	/**
106
	 * Clone the page.
107
	 *
108
	 * @param int $page_id The page ID
109
	 * @param string $name The cloned page name
110
	 * @return \SevenShores\Hubspot\Http\Response
111
	 */
112
    function clonePage($page_id, $name)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
113
    {
114
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/clone";
115
116
        $options['json'] = ['name' => $name];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
117
118
        return $this->client->request('post', $endpoint, $options);
119
    }
120
121
    /**
122
     * Determine if the auto-save buffer differs from the live page.
123
     *
124
     * @param int $page_id The page ID
125
     * @return \SevenShores\Hubspot\Http\Response
126
     */
127
    function hasBufferedChanges($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
128
    {
129
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/has-buffered-changes";
130
131
        return $this->client->request('get', $endpoint);
132
    }
133
134
    /**
135
     * Either publishes or cancels publishing based on the POSTed JSON.
136
     *
137
     * Allowable actions are: "push-buffer-live", "schedule-publish", "cancel-publish".
138
     * "push-buffer-live": copies the current contents of the auto-save buffer into the live object.
139
     * "schedule-publish": which pushes the buffer live and then sets up the content for publishing at
140
     *     the existing publish_date time.
141
     * "cancel-publish": cancels a previous schedule-publish action.
142
     *
143
     * @param int    $page_id The page ID
144
     * @param string $action  The publish action
145
     * @return \SevenShores\Hubspot\Http\Response
146
     */
147
    function publishAction($page_id, $action)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
148
    {
149
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/publish-action";
150
151
        $options['json'] = ['action' => $action];
152
153
        return $this->client->request('post', $endpoint, $options);
154
    }
155
156
    /**
157
     * Copies the contents of the auto-save buffer into the live page.
158
     *
159
     * @param int $page_id The page ID
160
     * @return \SevenShores\Hubspot\Http\Response
161
     */
162
    function pushBufferLive($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
163
    {
164
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/push-buffer-live";
165
166
        return $this->client->request('post', $endpoint);
167
    }
168
169
    /**
170
     * Restores a previously deleted page.
171
     *
172
     * @param int $page_id The page ID
173
     * @return \SevenShores\Hubspot\Http\Response
174
     */
175
    function restoreDeleted($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
176
    {
177
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/restore-deleted";
178
179
        return $this->client->request('post', $endpoint);
180
    }
181
182
    /**
183
     * Validates the auto-save buffer version of the page.
184
     *
185
     * @param int $page_id The page ID
186
     * @return \SevenShores\Hubspot\Http\Response
187
     */
188
    function validateBuffer($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
189
    {
190
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/validate-buffer";
191
192
        return $this->client->request('post', $endpoint);
193
    }
194
195
    /**
196
     * List previous versions of the page.
197
     *
198
     * @param int $page_id The page ID
199
     * @return \SevenShores\Hubspot\Http\Response
200
     */
201
    function versions($page_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
202
    {
203
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/versions";
204
205
        return $this->client->request('get', $endpoint);
206
    }
207
208
    /**
209
     * Restore a previous version of the page.
210
     *
211
     * @param int $page_id    The page ID
212
     * @param int $version_id The version ID
213
     * @return \SevenShores\Hubspot\Http\Response
214
     */
215 View Code Duplication
    function restoreVersion($page_id, $version_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
216
    {
217
        $endpoint = "https://api.hubapi.com/content/api/v2/pages/{$page_id}/versions/restore";
218
219
        $options['json'] = compact('version_id');
220
221
        return $this->client->request('post', $endpoint, $options);
222
    }
223
}
224