Completed
Push — master ( 128e80...6580ce )
by Ryan
07:12 queued 05:19
created

Companies::updateBatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Companies extends Resource
6
{
7
8
    /**
9
     * Create a company
10
     * @param array $properties Array of company properties.
11
     *
12
     * @see http://developers.hubspot.com/docs/methods/companies/create_company
13
     *
14
     * @return \SevenShores\Hubspot\Http\Response
15
     */
16
    function create($properties)
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/companies/v2/companies/';
19
        $options['json'] = ['properties' => $properties];
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...
20
21
        return $this->client->request('post', $endpoint, $options);
22
    }
23
24
    /**
25
     * Updates a company
26
     * @param int $id The company id.
27
     * @param array $properties The company properties to update.
28
     *
29
     * @see http://developers.hubspot.com/docs/methods/companies/update_company
30
     *
31
     * @return \SevenShores\Hubspot\Http\Response
32
     */
33 View Code Duplication
    function update($id, $properties)
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...
34
    {
35
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}";
36
        $options['json'] = ['properties' => $properties];
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...
37
38
        return $this->client->request('put', $endpoint, $options);
39
    }
40
41
    /**
42
     * @param array $companies The companies and properties.
43
     * @return \SevenShores\Hubspot\Http\Response
44
     */
45
    function updateBatch($companies)
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...
46
    {
47
        $endpoint = "https://api.hubapi.com/companies/v1/batch-async/update";
48
        $options['json'] = $companies;
49
50
        return $this->client->request('post', $endpoint, $options);
51
    }
52
53
    /**
54
     * Deletes a company
55
     * @param int $id The company id
56
     *
57
     * @see http://developers.hubspot.com/docs/methods/companies/delete_company
58
     *
59
     * @return \SevenShores\Hubspot\Http\Response
60
     */
61
    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...
62
    {
63
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}";
64
65
        return $this->client->request('delete', $endpoint);
66
    }
67
68
    /**
69
     * Returns all companies
70
     * @param array $params Array of optional parameters ['limit', 'offset', 'properties']
71
     *
72
     * @see http://developers.hubspot.com/docs/methods/companies/get-all-companies
73
     *
74
     * @return \SevenShores\Hubspot\Http\Response
75
     */
76
    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...
77
    {
78
        $endpoint = 'https://api.hubapi.com/companies/v2/companies/paged';
79
80
        $queryString = build_query_string($params);
81
82
        return $this->client->request('get', $endpoint, [], $queryString);
83
    }
84
85
    /**
86
     * Returns the recently modified companies
87
     * @param array $params Array of optional parameters ['count', 'offset']
88
     *
89
     * @see http://developers.hubspot.com/docs/methods/companies/get_companies_modified
90
     *
91
     * @return \SevenShores\Hubspot\Http\Response
92
     */
93
    function getRecentlyModified($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...
94
    {
95
        $endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/modified';
96
97
        $queryString = build_query_string($params);
98
99
        return $this->client->request('get', $endpoint, [], $queryString);
100
    }
101
102
    /**
103
     * Returns the recently created companies
104
     * @param array $params Array of optional parameters ['count', 'offset']
105
     *
106
     * @see http://developers.hubspot.com/docs/methods/companies/get_companies_created
107
     *
108
     * @return \SevenShores\Hubspot\Http\Response
109
     */
110
    function getRecentlyCreated($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...
111
    {
112
        $endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/created';
113
114
        $queryString = build_query_string($params);
115
116
        return $this->client->request('get', $endpoint, [], $queryString);
117
    }
118
119
    /**
120
     * Returns an array of companies that have a matching domain
121
     * @param string $domain The domain of the company eq. 'example.com'.
122
     *
123
     * @see http://developers.hubspot.com/docs/methods/companies/get_companies_by_domain
124
     *
125
     * @return \SevenShores\Hubspot\Http\Response
126
     */
127
    function getByDomain($domain)
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...
128
    {
129
        $endpoint = "https://api.hubapi.com/companies/v2/companies/domain/{$domain}";
130
131
        return $this->client->request('get', $endpoint);
132
    }
133
134
    /**
135
     * @param string $domain
136
     * @param array $properties
137
     * @param int $limit
138
     * @param int $offset
139
     *
140
     * @see https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain
141
     *
142
     * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
143
     */
144
    public function searchByDomain($domain, $properties = [], $limit = 100, $offset = 0)
145
    {
146
        $endpoint = "https://api.hubapi.com/companies/v2/domains/{$domain}/companies";
147
        $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...
148
            'limit' => $limit,
149
            'offset' => [
150
                'isPrimary' => true,
151
                'companyId' => $offset
152
            ],
153
            'requestOptions' => [
154
                'properties' => $properties
155
            ]
156
        ];
157
        return $this->client->request('post', $endpoint, $options);
158
    }
159
160
    /**
161
     * Returns a company with id $id
162
     * @param int $id
163
     *
164
     * @see http://developers.hubspot.com/docs/methods/companies/get_company
165
     *
166
     * @return \SevenShores\Hubspot\Http\Response
167
     */
168
    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...
169
    {
170
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}";
171
172
        return $this->client->request('get', $endpoint);
173
    }
174
175
    /**
176
     * Associates a given contact to a given company
177
     * If a contact is already associated to a different company, the contact will be added to the new company
178
     * @param int $contactId
179
     * @param int $companyId
180
     *
181
     * @see http://developers.hubspot.com/docs/methods/companies/add_contact_to_company
182
     *
183
     * @return \SevenShores\Hubspot\Http\Response
184
     */
185
    function addContact($contactId, $companyId)
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...
186
    {
187
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/contacts/{$contactId}";
188
189
        return $this->client->request('put', $endpoint);
190
    }
191
192
    /**
193
     * Returns an array of the associated contacts for the given company
194
     * @param int $companyId The id of the company.
195
     * @param array $params Array of optional parameters ['count', 'vidOffset']
196
     *
197
     * @see http://developers.hubspot.com/docs/methods/companies/get_company_contacts
198
     *
199
     * @return \SevenShores\Hubspot\Http\Response
200
     */
201
    function getAssociatedContacts($companyId, $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...
202
    {
203
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/contacts";
204
205
        $queryString = build_query_string($params);
206
207
        return $this->client->request('get', $endpoint, [], $queryString);
208
    }
209
210
    /**
211
     * Returns all of the contact IDs who are associated with the given company
212
     * @param int $companyId The id of the company.
213
     * @param array $params Array of optional parameters ['count', 'vidOffset']
214
     *
215
     * @see http://developers.hubspot.com/docs/methods/companies/get_company_contacts_by_id
216
     *
217
     * @return \SevenShores\Hubspot\Http\Response
218
     */
219
    function getAssociatedContactIds($companyId, $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...
220
    {
221
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/vids";
222
223
        $queryString = build_query_string($params);
224
225
        return $this->client->request('get', $endpoint, [], $queryString);
226
    }
227
228
    /**
229
     * Removes a contact from a company
230
     * @param int $contactId
231
     * @param int $companyId
232
     *
233
     * @see http://developers.hubspot.com/docs/methods/companies/remove_contact_from_company
234
     *
235
     * @return \SevenShores\Hubspot\Http\Response
236
     */
237
    function removeContact($contactId, $companyId)
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...
238
    {
239
        $endpoint = "https://api.hubapi.com/companies/v2/companies/{$companyId}/contacts/{$contactId}";
240
241
        return $this->client->request('delete', $endpoint);
242
    }
243
244
245
246
}
247