Completed
Pull Request — master (#167)
by
unknown
01:40
created

Tickets::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace SevenShores\Hubspot\Resources;
3
4
use SevenShores\Hubspot\Exceptions\HubspotException;
5
6
class Tickets extends Resource
7
{
8
    /**
9
     * @param array $ticket Array of deal properties.
10
     * @return mixed
11
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
12
     */
13
    function create(array $ticket)
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/crm-objects/v1/objects/tickets";
16
17
        $options['json'] = $ticket;
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
     * @param int $id The deal id.
24
     * @param array $ticket The deal properties to update.
25
     * @return mixed
26
     */
27
    function update($id, array $ticket)
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...
28
    {
29
        $endpoint = "https://api.hubapi.com/crm-objects/v1/objects/tickets/{$id}";
30
31
        $options['json'] = $ticket;
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...
32
33
        return $this->client->request('put', $endpoint, $options);
34
    }
35
36
    /**
37
     * @param array $params
38
     *
39
     * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
40
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
41
     */
42 View Code Duplication
    function getAll(array $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...
43
        $endpoint = "https://api.hubapi.com/crm-objects/v1/objects/tickets/paged";
44
45
        $queryString = build_query_string($params);
46
47
        return $this->client->request('get', $endpoint, [], $queryString);
48
    }
49
50
51
    /**
52
     * @param int $id
53
     * @return mixed
54
     */
55
    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...
56
    {
57
        $endpoint = "https://api.hubapi.com/crm-objects/v1/objects/tickets/{$id}";
58
59
        return $this->client->request('delete', $endpoint);
60
    }
61
62
    /**
63
     * @param int $id
64
     * @return mixed
65
     */
66
    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...
67
    {
68
        $endpoint = "https://api.hubapi.com/crm-objects/v1/objects/tickets/{$id}";
69
70
        return $this->client->request('get', $endpoint);
71
    }
72
73
    /**
74
     * @param array $params Optional parameters ['timestamp', 'changeType', 'objectId']
75
     * @return mixed
76
     */
77 View Code Duplication
    function getChangelog(array $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...
78
    {
79
        $endpoint = "https://api.hubapi.com/crm-objects/v1/change-log/tickets";
80
        $queryString = build_query_string($params);
81
82
        return $this->client->request('get', $endpoint, [], $queryString);
83
    }
84
85
}
86