Completed
Pull Request — master (#94)
by
unknown
02:26
created

Deals::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace SevenShores\Hubspot\Resources;
3
4
use SevenShores\Hubspot\Exceptions\HubspotException;
5
6
class Deals extends Resource
7
{
8
    /**
9
     * @param array $deal Array of deal properties.
10
     * @return mixed
11
     * @throws HubSpotException
12
     */
13
    function create(array $deal)
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/deals/v1/deal";
16
17
        $options['json'] = $deal;
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 $deal The deal properties to update.
25
     * @return mixed
26
     */
27 View Code Duplication
    function update($id, array $deal)
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $endpoint = "https://api.hubapi.com/deals/v1/deal/{$id}";
30
31
        $options['json'] = $deal;
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
        $endpoint = "https://api.hubapi.com/deals/v1/deal/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/deals/v1/deal/{$id}";
58
59
        return $this->client->request('delete', $endpoint);
60
    }
61
62
    /**
63
     * @param array $params Optional parameters ['limit', 'offset']
64
     * @return mixed
65
     */
66 View Code Duplication
    function getRecentlyModified(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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $endpoint = "https://api.hubapi.com/deals/v1/deal/recent/modified";
69
        $queryString = build_query_string($params);
70
71
        return $this->client->request('get', $endpoint, [], $queryString);
72
    }
73
74
    /**
75
     * @param array $params Optional parameters ['limit', 'offset']
76
     * @return mixed
77
     */
78
    function getRecentlyCreated(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...
79
    {
80
        $endpoint = "https://api.hubapi.com/deals/v1/deal/recent/created";
81
        $queryString = build_query_string($params);
82
83
        return $this->client->request('get', $endpoint, [], $queryString);
84
    }
85
86
    /**
87
     * @param int $id
88
     * @return mixed
89
     */
90
    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...
91
    {
92
        $endpoint = "https://api.hubapi.com/deals/v1/deal/{$id}";
93
94
        return $this->client->request('get', $endpoint);
95
    }
96
97
    /**
98
     * @param int $dealId
99
     * @param int|int[] $companyIds
100
     * @return mixed
101
     */
102 View Code Duplication
    function associateWithCompany($dealId, $companyIds)
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $endpoint = "https://api.hubapi.com/deals/v1/deal/{$dealId}/associations/COMPANY";
105
106
        $queryString = build_query_string(['id' => (array)$companyIds]);
107
108
        return $this->client->request('put', $endpoint, [], $queryString);
109
    }
110
111
    /**
112
     * @param int $dealId
113
     * @param int|int[] $companyIds
114
     * @return mixed
115
     */
116 View Code Duplication
    function disassociateFromCompany($dealId, $companyIds)
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $endpoint = "https://api.hubapi.com/deals/v1/deal/{$dealId}/associations/COMPANY";
119
120
        $queryString = build_query_string(['id' => (array)$companyIds]);
121
122
        return $this->client->request('delete', $endpoint, [], $queryString);
123
    }
124
125
    /**
126
     * @param int $dealId
127
     * @param int|int[] $contactIds
128
     * @return mixed
129
     */
130 View Code Duplication
    function associateWithContact($dealId, $contactIds)
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131
    {
132
        $endpoint = "https://api.hubapi.com/deals/v1/deal/{$dealId}/associations/CONTACT";
133
134
        $queryString = build_query_string(['id' => (array)$contactIds]);
135
136
        return $this->client->request('put', $endpoint, [], $queryString);
137
    }
138
    
139
    /**
140
     * @param int $contactId
141
     * @return mixed
142
     */
143
    function associatedWithContact($contactId)
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...
144
    {
145
        $endpoint = "https://api.hubapi.com/deals/v1/deal/associated/contact/{$contactId}";
146
147
        return $this->client->request('get', $endpoint);
148
    }
149
150
    /**
151
     * @param int $dealId
152
     * @param int|int[] $contactIds
153
     * @return mixed
154
     */
155 View Code Duplication
    function disassociateFromContact($dealId, $contactIds)
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
156
    {
157
        $endpoint = "https://api.hubapi.com/deals/v1/deal/{$dealId}/associations/CONTACT";
158
159
        $queryString = build_query_string(['id' => (array)$contactIds]);
160
161
        return $this->client->request('delete', $endpoint, [], $queryString);
162
    }
163
}
164