ContactProperties   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 171
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 6 1
A get() 0 6 1
A create() 0 8 1
A update() 0 9 1
A delete() 0 6 1
A getGroups() 0 8 1
A createGroup() 0 8 1
A updateGroup() 0 9 1
A deleteGroup() 0 6 1
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class ContactProperties extends Resource
6
{
7
    /**
8
     * Get all Contact properties.
9
     *
10
     * Properties in HubSpot are fields that have been created, in this case for deals in a given portal.
11
     * This endpoint will return all of the contacts properties, including their definition, for a given portal.
12
     *
13
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/get_contacts_properties
14
     *
15
     * @return \SevenShores\Hubspot\Http\Response
16
     */
17
    function all()
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...
18
    {
19
        $endpoint = 'https://api.hubapi.com/contacts/v2/properties';
20
21
        return $this->client->request('get', $endpoint);
22
    }
23
24
    /**
25
     * Get a Contact Property.
26
     *
27
     * Returns a JSON object representing the definition for a given contact property.
28
     *
29
     * @see http://developers.hubspot.com/docs/methods/companies/get_contact_property
30
     *
31
     * @param string $name The name of the property.
32
     * @return \SevenShores\Hubspot\Http\Response
33
     */
34
    function get($name)
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...
35
    {
36
        $endpoint = "https://api.hubapi.com/contacts/v2/properties/named/{$name}";
37
38
        return $this->client->request('get', $endpoint);
39
    }
40
41
    /**
42
     * Create a contact property.
43
     *
44
     * Create a property on every contact object to store a specific piece of data. In the example below,
45
     * we want to store an invoice number on a separate field on deals.
46
     *
47
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/create_contacts_property
48
     *
49
     * @param array $property
50
     * @return \SevenShores\Hubspot\Http\Response
51
     */
52
    function create($property)
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/contacts/v2/properties";
55
56
        $options['json'] = $property;
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
58
        return $this->client->request('post', $endpoint, $options);
59
    }
60
61
    /**
62
     * Update a contact property.
63
     *
64
     * Update a specified contact property.
65
     *
66
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/update_contact_property
67
     *
68
     * @param string $name
69
     * @param array  $property
70
     * @return \SevenShores\Hubspot\Http\Response
71
     */
72
    function update($name, $property)
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...
73
    {
74
        $endpoint = "https://api.hubapi.com/contacts/v2/properties/named/{$name}";
75
76
        $property['name'] = $name;
77
        $options['json'] = $property;
78
79
        return $this->client->request('put', $endpoint, $options);
80
    }
81
82
    /**
83
     * Delete a contact property.
84
     *
85
     * For a portal, delete an existing contact property.
86
     *
87
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/delete_contact_property
88
     *
89
     * @param string $name
90
     * @return \SevenShores\Hubspot\Http\Response
91
     */
92
    function delete($name)
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...
93
    {
94
        $endpoint = "https://api.hubapi.com/contacts/v2/properties/named/{$name}";
95
96
        return $this->client->request('delete', $endpoint);
97
    }
98
99
    /**
100
     * Get contact property groups.
101
     *
102
     * Returns all of the contact property groups for a given portal.
103
     *
104
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/get_contact_property_groups
105
     *
106
     * @param bool $includeProperties
107
     * @return \SevenShores\Hubspot\Http\Response
108
     */
109
    function getGroups($includeProperties = false)
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...
110
    {
111
        $endpoint = "https://api.hubapi.com/contacts/v2/groups";
112
113
        $queryString = build_query_string(['includeProperties' => $includeProperties]);
114
115
        return $this->client->request('get', $endpoint, [], $queryString);
116
    }
117
118
    /**
119
     * Create a contact property group.
120
     *
121
     * Create a new contact property group to gather like contact-level data. Property groups allow you to more
122
     * easily manage properties in a given portal and make contact records easier to parse for the user.
123
     *
124
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/create_contacts_property_group
125
     *
126
     * @param array $group Group properties
127
     * @return \SevenShores\Hubspot\Http\Response
128
     */
129
    function createGroup($group)
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...
130
    {
131
        $endpoint = "https://api.hubapi.com/contacts/v2/groups";
132
133
        $options['json'] = $group;
134
135
        return $this->client->request('post', $endpoint, $options);
136
    }
137
138
    /**
139
     * Update a property group.
140
     *
141
     * Update a previously created contact property group.
142
     *
143
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/update_contact_property_group
144
     *
145
     * @param string $name
146
     * @param array  $group
147
     * @return \SevenShores\Hubspot\Http\Response
148
     */
149
    function updateGroup($name, $group)
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...
150
    {
151
        $endpoint = "https://api.hubapi.com/contacts/v2/groups/named/{$name}";
152
153
        $group['name'] = $name;
154
        $options['json'] = $group;
155
156
        return $this->client->request('put', $endpoint, $options);
157
    }
158
159
    /**
160
     * Delete a property group.
161
     *
162
     * Delete an existing contact property group.
163
     *
164
     * @see http://developers.hubspot.com/docs/methods/contacts/v2/delete_contact_property_group
165
     *
166
     * @param string $name
167
     * @return \SevenShores\Hubspot\Http\Response
168
     */
169
    function deleteGroup($name)
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...
170
    {
171
        $endpoint = "https://api.hubapi.com/contacts/v2/groups/named/{$name}";
172
173
        return $this->client->request('delete', $endpoint);
174
    }
175
}
176