Engagements   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 142
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 13 1
A recent() 0 8 1
A update() 0 16 2
A delete() 0 6 1
A get() 0 6 1
A all() 0 8 1
A associate() 0 6 1
A associated() 0 6 1
A activityTypes() 0 6 1
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
use SevenShores\Hubspot\Exceptions\BadRequest;
6
7
class Engagements extends Resource
8
{
9
    /**
10
     * @param array $engagement Array of engagement engagement.
11
     * @param array $associations Array of engagement associations.
12
     * @param array $metadata Array of engagement metadata.
13
     * @param array $attachments Array of engagement attachments.
14
     * @return \SevenShores\Hubspot\Http\Response
15
     */
16
    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...
17
    {
18
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements";
19
20
        $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...
21
            'engagement' => $engagement,
22
            'associations' => $associations,
23
            'metadata' => $metadata,
24
            'attachments' => $attachments
25
        ];
26
27
        return $this->client->request('post', $endpoint, $options);
28
    }
29
30
    /**
31
     * Returns all recently created or updated engagements.
32
     *
33
     * @param array $params Array of optional parameters ['count', 'offset', 'since]
34
     *
35
     * @see https://developers.hubspot.com/docs/methods/engagements/get-recent-engagements
36
     *
37
     * @return \SevenShores\Hubspot\Http\Response
38
     */
39
    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...
40
    {
41
        $endpoint = 'https://api.hubapi.com/engagements/v1/engagements/recent/modified';
42
43
        $queryString = build_query_string($params);
44
45
        return $this->client->request('get', $endpoint, [], $queryString);
46
    }
47
48
    /**
49
     * @param int $id The engagement id.
50
     * @param array $engagement The engagement engagement to update.
51
     * @param array $metadata The engagement metadata to update.
52
     * @param string $method
53
     * @return \SevenShores\Hubspot\Http\Response
54
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
55
     */
56
    function update($id, $engagement, $metadata, $method = 'patch')
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
        $availableMethods = ['put', 'patch'];
59
60
        if (! \in_array($method, $availableMethods)) {
61
            throw new BadRequest('Method name '.$method.' is invalid', 400);
62
        }
63
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
64
65
        $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...
66
            'engagement' => $engagement,
67
            'metadata' => $metadata,
68
        ];
69
70
        return $this->client->request($method, $endpoint, $options);
71
    }
72
73
    /**
74
     * @param int $id
75
     * @return \SevenShores\Hubspot\Http\Response
76
     */
77
    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...
78
    {
79
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
80
81
        return $this->client->request('delete', $endpoint);
82
    }
83
84
    /**
85
     * @param int $id
86
     * @return \SevenShores\Hubspot\Http\Response
87
     */
88
    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...
89
    {
90
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
91
92
        return $this->client->request('get', $endpoint);
93
    }
94
95
    /**
96
     * Returns all engagements.
97
     *
98
     * @param array $params Array of optional parameters ['limit', 'offset']
99
     *
100
     * @see http://developers.hubspot.com/docs/methods/engagements/get-all-engagements
101
     *
102
     * @return \SevenShores\Hubspot\Http\Response
103
     */
104
    public function all($params = [])
105
    {
106
        $endpoint = 'https://api.hubapi.com/engagements/v1/engagements/paged';
107
108
        $queryString = build_query_string($params);
109
110
        return $this->client->request('get', $endpoint, [], $queryString);
111
    }
112
113
    /**
114
     * @param int $id
115
     * @param string $object_type
116
     * @param int $object_id
117
     * @return \SevenShores\Hubspot\Http\Response
118
     **/
119
    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...
120
    {
121
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}/associations/{$object_type}/{$object_id}";
122
123
        return $this->client->request('put', $endpoint);
124
    }
125
126
    /**
127
     * @param string $object_type
128
     * @param int $object_id
129
     * @param array $params Array of optional parameters ['limit', 'offset']
130
     * @return \SevenShores\Hubspot\Http\Response
131
     **/
132
    function associated($object_type, $object_id, $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...
133
    {
134
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/associated/{$object_type}/{$object_id}/paged";
135
        $queryString = build_query_string($params);
136
        return $this->client->request('get', $endpoint, [], $queryString);
137
    }
138
139
    /**
140
     * @return \SevenShores\Hubspot\Http\Response
141
     */
142
    function activityTypes()
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...
143
    {
144
        $endpoint = "https://api.hubapi.com/engagements/v1/activity-types";
145
146
        return $this->client->request('get', $endpoint);
147
    }
148
}
149