ContactLists   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 194
Duplicated Lines 13.92 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 27
loc 194
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 2

13 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A update() 8 8 1
A delete() 0 6 1
A all() 0 8 1
A getById() 0 6 1
A getBatchByIds() 0 8 1
A getAllStatic() 0 8 1
A getAllDynamic() 0 8 1
A contacts() 0 8 1
A recentContacts() 0 8 1
A refresh() 0 6 1
A addContact() 11 11 1
A removeContact() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class ContactLists extends Resource
6
{
7
    /**
8
     * Create a new contact list.
9
     *
10
     * @param array $list Contact list properties.
11
     * @return \SevenShores\Hubspot\Http\Response
12
     */
13
    function create($list)
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/contacts/v1/lists';
16
17
        $options['json'] = $list;
18
19
        return $this->client->request('post', $endpoint, $options);
20
    }
21
22
    /**
23
     * Update a contact list.
24
     *
25
     * @param int   $id   The contact list id.
26
     * @param array $list The contact list properties to update.
27
     * @return \SevenShores\Hubspot\Http\Response
28
     */
29 View Code Duplication
    function update($id, $list)
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...
30
    {
31
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$id}";
32
33
        $options['json'] = $list;
34
35
        return $this->client->request('post', $endpoint, $options);
36
    }
37
38
    /**
39
     * Delete a contact list.
40
     *
41
     * @param int $id
42
     * @return \SevenShores\Hubspot\Http\Response
43
     */
44
    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...
45
    {
46
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$id}";
47
48
        return $this->client->request('delete', $endpoint);
49
    }
50
51
    /**
52
     * Get a set of contact lists.
53
     *
54
     * @param array $params ['count', 'offset']
55
     * @return \SevenShores\Hubspot\Http\Response
56
     */
57
    function all($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...
58
    {
59
        $endpoint = "https://api.hubapi.com/contacts/v1/lists";
60
61
        $queryString = build_query_string($params);
62
63
        return $this->client->request('get', $endpoint, [], $queryString);
64
    }
65
66
    /**
67
     * @param int $id
68
     * @return \SevenShores\Hubspot\Http\Response
69
     */
70
    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...
71
    {
72
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$id}";
73
74
        return $this->client->request('get', $endpoint);
75
    }
76
77
    /**
78
     * @param array $ids
79
     * @return \SevenShores\Hubspot\Http\Response
80
     */
81
    function getBatchByIds($ids)
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...
82
    {
83
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/batch";
84
85
        $queryString = build_query_string(['listId' => $ids]);
86
87
        return $this->client->request('get', $endpoint, [], $queryString);
88
    }
89
90
    /**
91
     * @param array $params Optional parameters ['count', 'offset']
92
     * @return \SevenShores\Hubspot\Http\Response
93
     */
94
    function getAllStatic($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...
95
    {
96
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/static";
97
98
        $queryString = build_query_string($params);
99
100
        return $this->client->request('get', $endpoint, [], $queryString);
101
    }
102
103
    /**
104
     * @param array $params Optional parameters ['count', 'offset']
105
     * @return \SevenShores\Hubspot\Http\Response
106
     */
107
    function getAllDynamic($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...
108
    {
109
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/dynamic";
110
111
        $queryString = build_query_string($params);
112
113
        return $this->client->request('get', $endpoint, [], $queryString);
114
    }
115
116
    /**
117
     * Get contacts in a list.
118
     *
119
     * @param int   $id     List id
120
     * @param array $params Optional parameters
121
     *                      { count, vidOffset, property, propertyMode, formSubmissionMode, showListMemberships }
122
     * @return \SevenShores\Hubspot\Http\Response
123
     */
124
    function contacts($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...
125
    {
126
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$id}/contacts/all";
127
128
        $queryString = build_query_string($params);
129
130
        return $this->client->request('get', $endpoint, [], $queryString);
131
    }
132
133
    /**
134
     * Get recently added contact from a list.
135
     *
136
     * @param int   $id List id
137
     * @param array $params
138
     * @return \SevenShores\Hubspot\Http\Response
139
     */
140
    function recentContacts($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...
141
    {
142
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$id}/contacts/recent";
143
144
        $queryString = build_query_string($params);
145
146
        return $this->client->request('get', $endpoint, [], $queryString);
147
    }
148
149
    /**
150
     * Refresh a list.
151
     *
152
     * @param int $id List id
153
     * @return \SevenShores\Hubspot\Http\Response
154
     */
155
    function refresh($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...
156
    {
157
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$id}/refresh";
158
159
        return $this->client->request('post', $endpoint);
160
    }
161
162
    /**
163
     * Add a contact to a list.
164
     *
165
     * @param int   $list_id
166
     * @param array $contact_ids
167
     * @param array $emails
168
     * @return \SevenShores\Hubspot\Http\Response
169
     */
170 View Code Duplication
    function addContact($list_id, $contact_ids, $emails = [])
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...
171
    {
172
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$list_id}/add";
173
174
        $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...
175
          'vids' => $contact_ids,
176
          'emails' => $emails,
177
        ];
178
179
        return $this->client->request('post', $endpoint, $options);
180
    }
181
182
    /**
183
     * Remove a contact from a list.
184
     *
185
     * @param int   $list_id
186
     * @param array $contact_ids
187
     * @return \SevenShores\Hubspot\Http\Response
188
     */
189 View Code Duplication
    function removeContact($list_id, $contact_ids)
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...
190
    {
191
        $endpoint = "https://api.hubapi.com/contacts/v1/lists/{$list_id}/remove";
192
193
        $options['json'] = ['vids' => $contact_ids];
194
195
        return $this->client->request('post', $endpoint, $options);
196
    }
197
198
}
199