BlogPosts   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 239
Duplicated Lines 10.04 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 24
loc 239
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 2

16 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A all() 0 8 1
A update() 0 8 1
A delete() 0 6 1
A getById() 0 6 1
A updateAutoSaveBuffer() 0 8 1
A getAutoSaveBufferContents() 0 6 1
A clonePost() 8 8 1
A hasBufferedChanges() 0 6 1
A publishAction() 8 8 1
A pushBufferLive() 0 6 1
A restoreDeleted() 0 6 1
A validateBuffer() 0 6 1
A versions() 0 6 1
A getVersion() 0 6 1
A restoreVersion() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class BlogPosts extends Resource
6
{
7
    /**
8
     * Create a new blog post.
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/blog-posts';
16
17
        $options['json'] = $params;
18
19
        return $this->client->request('post', $endpoint, $options);
20
    }
21
22
    /**
23
     * Get all blog posts.
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/blog-posts";
31
32
        $queryString = build_query_string($params);
33
34
        return $this->client->request('get', $endpoint, [], $queryString);
35
    }
36
37
    /**
38
     * Update a blog post.
39
     *
40
     * @param  int   $id     The blog post id.
41
     * @param  array $params The blog post fields to update.
42
     * @return \SevenShores\Hubspot\Http\Response
43
     */
44
    function update($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/blog-posts/{$id}";
47
48
        $options['json'] = $params;
49
50
        return $this->client->request('put', $endpoint, $options);
51
    }
52
53
    /**
54
     * Delete a blog post.
55
     *
56
     * @param  int $id
57
     * @return \SevenShores\Hubspot\Http\Response
58
     */
59
    function delete($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/blog-posts/{$id}";
62
63
        return $this->client->request('delete', $endpoint);
64
    }
65
66
    /**
67
     * Get a specific blog post.
68
     *
69
     * @param  int $id
70
     * @return \SevenShores\Hubspot\Http\Response
71
     */
72
    function getById($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/blog-posts/{$id}";
75
76
        return $this->client->request('get', $endpoint);
77
    }
78
79
    /**
80
     * Updates the auto-save buffer. Live objects will not be impacted.
81
     *
82
     * @see http://developers.hubspot.com/docs/methods/blogv2/put_blog_posts_blog_post_id_buffer
83
     *
84
     * @param  int   $id     The blog post ID.
85
     * @param  array $params Allowed parameters.
86
     * @return \SevenShores\Hubspot\Http\Response
87
     */
88
    function updateAutoSaveBuffer($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...
89
    {
90
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/buffer";
91
92
        $options['json'] = $params;
93
94
        return $this->client->request('put', $endpoint, $options);
95
    }
96
97
    /**
98
     * Gets the current contents of the auto-save buffer.
99
     *
100
     * @param  int $id The blog post ID
101
     * @return \SevenShores\Hubspot\Http\Response
102
     */
103
    function getAutoSaveBufferContents($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...
104
    {
105
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/buffer";
106
107
        return $this->client->request('get', $endpoint);
108
    }
109
110
    /**
111
     * Clone the blog post.
112
     * Requires including a request body of {"name": "New Page Name"}
113
     *
114
     * @param  int $id The blog post ID
115
     * @param  string $name The cloned post name
116
     * @return \SevenShores\Hubspot\Http\Response
117
     */
118 View Code Duplication
    function clonePost($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...
119
    {
120
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/clone";
121
122
        $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...
123
124
        return $this->client->request('post', $endpoint, $options);
125
    }
126
127
    /**
128
     * Determine if the auto-save buffer differs from the live blog post.
129
     *
130
     * @param  int $id The blog post ID
131
     * @return \SevenShores\Hubspot\Http\Response
132
     */
133
    function hasBufferedChanges($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...
134
    {
135
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/has-buffered-changes";
136
137
        return $this->client->request('get', $endpoint);
138
    }
139
140
    /**
141
     * Either publishes or cancels publishing based on the POSTed JSON.
142
     *
143
     * Allowable actions are: "push-buffer-live", "schedule-publish", "cancel-publish".
144
     * "push-buffer-live": copies the current contents of the auto-save buffer into the live object.
145
     * "schedule-publish": which pushes the buffer live and then sets up the content for publishing at
146
     *     the existing publish_date time.
147
     * "cancel-publish": cancels a previous schedule-publish action.
148
     *
149
     * @param  int    $id     The blog post ID
150
     * @param  string $action The publish action
151
     * @return \SevenShores\Hubspot\Http\Response
152
     */
153 View Code Duplication
    function publishAction($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...
154
    {
155
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/publish-action";
156
157
        $options['json'] = ['action' => $action];
158
159
        return $this->client->request('post', $endpoint, $options);
160
    }
161
162
    /**
163
     * Copies the contents of the auto-save buffer into the live blog post.
164
     *
165
     * @param  int $id The blog post ID
166
     * @return \SevenShores\Hubspot\Http\Response
167
     */
168
    function pushBufferLive($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...
169
    {
170
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/push-buffer-live";
171
172
        return $this->client->request('post', $endpoint);
173
    }
174
175
    /**
176
     * Restores a previously deleted blog post.
177
     *
178
     * @param  int $id The blog post ID
179
     * @return \SevenShores\Hubspot\Http\Response
180
     */
181
    function restoreDeleted($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...
182
    {
183
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/restore-deleted";
184
185
        return $this->client->request('post', $endpoint);
186
    }
187
188
    /**
189
     * Validates the auto-save buffer version of the blog post.
190
     *
191
     * @param  int $id The blog post ID
192
     * @return \SevenShores\Hubspot\Http\Response
193
     */
194
    function validateBuffer($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...
195
    {
196
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/validate-buffer";
197
198
        return $this->client->request('post', $endpoint);
199
    }
200
201
    /**
202
     * List previous versions of the blog post.
203
     *
204
     * @param  int $id The blog post ID
205
     * @return \SevenShores\Hubspot\Http\Response
206
     */
207
    function versions($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...
208
    {
209
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$id}/versions";
210
211
        return $this->client->request('get', $endpoint);
212
    }
213
214
    /**
215
     * Get a previous version of the blog post.
216
     *
217
     * @param int $post_id    The blog post ID
218
     * @param int $version_id The version ID
219
     * @return \SevenShores\Hubspot\Http\Response
220
     */
221
    function getVersion($post_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...
222
    {
223
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$post_id}/versions/{$version_id}";
224
225
        return $this->client->request('get', $endpoint);
226
    }
227
228
    /**
229
     * Restore a previous version of the blog post.
230
     *
231
     * @param int $post_id    The blog post ID
232
     * @param int $version_id The version ID
233
     * @return \SevenShores\Hubspot\Http\Response
234
     */
235 View Code Duplication
    function restoreVersion($post_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...
236
    {
237
        $endpoint = "https://api.hubapi.com/content/api/v2/blog-posts/{$post_id}/versions/restore";
238
239
        $options['json'] = compact('version_id');
240
241
        return $this->client->request('post', $endpoint, $options);
242
    }
243
}
244