Completed
Pull Request — master (#46)
by
unknown
02:21
created

BlogAuthors::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Fungku\HubSpot\Api;
4
5
class BlogAuthors extends Api
6
{
7
    /**
8
     * Create a new blog author.
9
     *
10
     * @param  array $params Optional Parameters.
11
     * @return \Fungku\HubSpot\Http\Response
12
     */
13
    public function create($params = [])
14
    {
15
        $endpoint = '/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->request('post', $endpoint, $options);
20
    }
21
22
    /**
23
     * Get all blog authors.
24
     *
25
     * @param  array $params Optional parameters.
26
     * @return \Fungku\HubSpot\Http\Response
27
     */
28
    public function all($params = [])
29
    {
30
        $endpoint = '/blogs/v3/blog-authors';
31
32
        $queryString = $this->buildQueryString($params);
33
34
        return $this->request('get', $endpoint, [], $queryString);
35
    }
36
37
    /**
38
     * Search blog authors.
39
     *
40
     * @param string $query     Search query
0 ignored issues
show
Bug introduced by
There is no parameter named $query. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
     * @param array $params     Optional parameters.
42
     * @return \Fungku\HubSpot\Http\Response
43
     */
44 View Code Duplication
    public function search($q = '', $params = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $endpoint = '/blogs/v3/blog-authors/search';
47
48
        $params['q'] = $q;
49
50
        $queryString = $this->buildQueryString($params);
51
52
        return $this->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 \Fungku\HubSpot\Http\Response
61
     */
62
    public function update($id, $params = [])
63
    {
64
        $endpoint = "/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->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 \Fungku\HubSpot\Http\Response
76
     */
77
    public function delete($id)
78
    {
79
        $endpoint = "/blogs/v3/blog-authors/{$id}";
80
81
        return $this->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 \Fungku\HubSpot\Http\Response
89
     */
90
    public function getById($id)
91
    {
92
        $endpoint = "/blogs/v3/blog-authors/{$id}";
93
94
        return $this->request('get', $endpoint);
95
    }
96
97
}
98