Completed
Pull Request — master (#44)
by
unknown
02:31
created

BlogTopics::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Fungku\HubSpot\Api;
4
5
class BlogTopics extends Api
6
{
7
8
    /**
9
     * Get all the blog topcis
10
     *
11
     * @param  array $params Optional parameters ['name','slug','limit','offset']
12
     * @return \Fungku\HubSpot\Http\Response
13
     */
14
    public function all($params = [])
15
    {
16
17
        $endpoint = '/blogs/v3/topics';
18
19
        $queryString = $this->buildQueryString($params);
20
21
        return $this->request('get', $endpoint, [], $queryString);
22
    }
23
24
    /**
25
     * Search a topic by the query. $query will match name and slug partially
26
     *
27
     * @link http://developers.hubspot.com/docs/methods/blog/v3/search-blog-topics
28
     *
29
     * @param string $query  Search query
30
     * @param array $params Array of optional parameters ['name','slug','limit', 'offset', 'active', 'blog']
31
     * @return \Fungku\HubSpot\Http\Response
32
     */
33 View Code Duplication
    public function search($query, $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...
34
    {
35
        $endpoint = '/blogs/v3/topics/search';
36
37
        $params['q'] = $query;
38
39
        $queryString = $this->buildQueryString($params);
40
41
        return $this->request('get', $endpoint, [], $queryString);
42
    }
43
44
    /**
45
     * @param int $id
46
     * @return \Fungku\HubSpot\Http\Response
47
     */
48
    public function getById($id)
49
    {
50
        $endpoint = "/blogs/v3/topics/{$id}";
51
52
        return $this->request('get', $endpoint);
53
    }
54
55
    /**
56
     * Create a new blog topic.
57
     *
58
     * @param string $name Name of the topic
59
     * @param  array $params Optional Parameters.
60
     * @return \Fungku\HubSpot\Http\Response
61
     */
62 View Code Duplication
    public function create($name, $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...
63
    {
64
        $endpoint = '/blogs/v3/topics';
65
66
        $params['name'] = $name;
67
68
        $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...
69
70
        return $this->request('post', $endpoint, $options);
71
    }
72
73
    /**
74
     * Update a blog topic.
75
     *
76
     * @param  int   $id     The blog topic id.
77
     * @param  array $params The blog topic fields to update.
78
     * @return \Fungku\HubSpot\Http\Response
79
     */
80 View Code Duplication
    public function update($id, $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...
81
    {
82
        $endpoint = "/blogs/v3/topics/{$id}";
83
84
        $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...
85
86
        return $this->request('put', $endpoint, $options);
87
    }
88
89
    /**
90
     * Delete a blog topic.
91
     *
92
     * @param  int $id
93
     * @return \Fungku\HubSpot\Http\Response
94
     */
95
    public function delete($id)
96
    {
97
        $endpoint = "/blogs/v3/topics/{$id}";
98
99
        return $this->request('delete', $endpoint);
100
    }
101
102
    /**
103
     * Group blog topics
104
     *
105
     * @param array $topicIds Array of topic ids
106
     * @param string $groupedTopicName New name of the group
107
     * @return \Fungku\HubSpot\Http\Response
108
     */
109
    public function merge($topicIds, $groupedTopicName)
110
    {
111
        $endpoint = "/blogs/v3/topics/group-topics";
112
113
        $options['json'] = [
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...
114
            'topicIds' => $topicIds,
115
            'groupedTopicName' => $groupedTopicName
116
        ];
117
118
        return $this->request('post', $endpoint, $options);
119
    }
120
}
121