Completed
Push — master ( e222f2...70f1e1 )
by Ryan
01:36
created

Engagements::recent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Engagements extends Resource
6
{
7
    /**
8
     * @param array $engagement Array of engagement engagement.
9
     * @param array $associations Array of engagement associations.
10
     * @param array $metadata Array of engagement metadata.
11
     * @param array $attachments Array of engagement attachments.
12
     * @return \SevenShores\Hubspot\Http\Response
13
     */
14
    function create($engagement, $associations, $metadata, $attachments = array())
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...
15
    {
16
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements";
17
18
        $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...
19
            'engagement' => $engagement,
20
            'associations' => $associations,
21
            'metadata' => $metadata,
22
            'attachments' => $attachments
23
        ];
24
25
        return $this->client->request('post', $endpoint, $options);
26
    }
27
    
28
    /**
29
     * Returns all recently created or updated engagements.
30
     *
31
     * @param array $params Array of optional parameters ['count', 'offset', 'since]
32
     *
33
     * @see https://developers.hubspot.com/docs/methods/engagements/get-recent-engagements
34
     *
35
     * @return \SevenShores\Hubspot\Http\Response
36
     */
37
    function recent($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...
38
    {
39
        $endpoint = 'https://api.hubapi.com/engagements/v1/engagements/recent/modified';
40
41
        $queryString = build_query_string($params);
42
43
        return $this->client->request('get', $endpoint, [], $queryString);
44
    }
45
46
    /**
47
     * @param int   $id         The engagement id.
48
     * @param array $engagement The engagement engagement to update.
49
     * @param array $metadata The engagement metadata to update.
50
     * @return \SevenShores\Hubspot\Http\Response
51
     */
52 View Code Duplication
    function update($id, $engagement, $metadata)
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...
53
    {
54
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
55
56
        $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...
57
            'engagement' => $engagement,
58
            'metadata' => $metadata,
59
        ];
60
61
        return $this->client->request('put', $endpoint, $options);
62
    }
63
64
    /**
65
     * @param int $id
66
     * @return \SevenShores\Hubspot\Http\Response
67
     */
68
    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...
69
    {
70
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
71
72
        return $this->client->request('delete', $endpoint);
73
    }
74
75
    /**
76
     * @param int $id
77
     * @return \SevenShores\Hubspot\Http\Response
78
     */
79
    function get($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...
80
    {
81
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
82
83
        return $this->client->request('get', $endpoint);
84
    }
85
86
    /**
87
     * Returns all engagements.
88
     *
89
     * @param array $params Array of optional parameters ['limit', 'offset']
90
     *
91
     * @see http://developers.hubspot.com/docs/methods/engagements/get-all-engagements
92
     *
93
     * @return \SevenShores\Hubspot\Http\Response
94
     */
95
    public function all($params = [])
96
    {
97
        $endpoint = 'https://api.hubapi.com/engagements/v1/engagements/paged';
98
99
        $queryString = build_query_string($params);
100
101
        return $this->client->request('get', $endpoint, [], $queryString);
102
    }
103
104
    /**
105
     * @param int $id
106
     * @param string $object_type
107
     * @param int $object_id
108
     * @return \SevenShores\Hubspot\Http\Response
109
     **/
110
    function associate($id, $object_type, $object_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...
111
    {
112
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}/associations/{$object_type}/{$object_id}";
113
114
        return $this->client->request('put', $endpoint);
115
    }
116
    
117
    /**
118
     * @param string $object_type
119
     * @param int $object_id
120
     * @return \SevenShores\Hubspot\Http\Response
121
     **/
122
    function associated($object_type, $object_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...
123
    {
124
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/associated/{$object_type}/{$object_id}/paged";
125
126
        return $this->client->request('get', $endpoint);
127
    }
128
}
129