Keywords   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 8 1
A getById() 0 6 1
A create() 0 8 1
A delete() 0 6 1
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Keywords extends Resource
6
{
7
    /**
8
     * Get all keywords.
9
     *
10
     * @param string $search Optional search query.
11
     * @return \SevenShores\Hubspot\Http\Response
12
     */
13
    function all($search = null)
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/keywords/v1/keywords';
16
17
        $queryString = build_query_string(['search' => $search]);
18
19
        return $this->client->request('get', $endpoint, [], $queryString);
20
    }
21
22
    /**
23
     * Get a keyword.
24
     *
25
     * @param string $keyword_guid
26
     * @return \SevenShores\Hubspot\Http\Response
27
     */
28
    function getById($keyword_guid)
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/keywords/v1/keywords/{$keyword_guid}";
31
32
        return $this->client->request('get', $endpoint);
33
    }
34
35
    /**
36
     * Create a new keyword.
37
     *
38
     * @param array $keyword
39
     * @return \SevenShores\Hubspot\Http\Response
40
     */
41
    function create($keyword)
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...
42
    {
43
        $endpoint = "https://api.hubapi.com/keywords/v1/keywords";
44
45
        $options['json'] = $keyword;
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...
46
47
        return $this->client->request('put', $endpoint, $options);
48
    }
49
50
    /**
51
     * Delete a keyword.
52
     *
53
     * @param string $keyword_guid
54
     * @return \SevenShores\Hubspot\Http\Response
55
     */
56
    function delete($keyword_guid)
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...
57
    {
58
        $endpoint = "https://api.hubapi.com/keywords/v1/keywords/{$keyword_guid}";
59
60
        return $this->client->request('delete', $endpoint);
61
    }
62
63
}
64