BlogAuthors::getById()   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 BlogAuthors extends Resource
6
{
7
    /**
8
     * Create a new blog author.
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/blogs/v3/blog-authors';
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 blog authors.
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/blogs/v3/blog-authors';
31
32
        $queryString = build_query_string($params);
33
34
        return $this->client->request('get', $endpoint, [], $queryString);
35
    }
36
37
    /**
38
     * Search blog authors.
39
     *
40
     * @param string $q         Search query
41
     * @param array $params     Optional parameters.
42
     * @return \SevenShores\Hubspot\Http\Response
43
     */
44
    function search($q = '', $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/blogs/v3/blog-authors/search';
47
48
        $params['q'] = $q;
49
50
        $queryString = build_query_string($params);
51
52
        return $this->client->request('get', $endpoint, [], $queryString);
53
    }
54
55
    /**
56
     * Update a blog author.
57
     *
58
     * @param  int   $id     Unique identifier for a blog author.
59
     * @param  array $params Fields to update.
60
     * @return \SevenShores\Hubspot\Http\Response
61
     */
62
    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...
63
    {
64
        $endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}";
65
66
        $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...
67
68
        return $this->client->request('put', $endpoint, $options);
69
    }
70
71
    /**
72
     * Delete a blog author.
73
     *
74
     * @param  int $id  Unique identifier for the blog author to delete.
75
     * @return \SevenShores\Hubspot\Http\Response
76
     */
77
    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...
78
    {
79
        $endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}";
80
81
        return $this->client->request('delete', $endpoint);
82
    }
83
84
    /**
85
     * Get a specific blog author.
86
     *
87
     * @param  int $id  Unique identifier for a blog author.
88
     * @return \SevenShores\Hubspot\Http\Response
89
     */
90
    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...
91
    {
92
        $endpoint = "https://api.hubapi.com/blogs/v3/blog-authors/{$id}";
93
94
        return $this->client->request('get', $endpoint);
95
    }
96
97
}
98