Email::subscriptionStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Email extends Resource
6
{
7
    /**
8
     * Get email subscription types for a portal.
9
     *
10
     * @param int $portal_id
11
     * @return \SevenShores\Hubspot\Http\Response
12
     */
13
    function subscriptions($portal_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...
14
    {
15
        $endpoint = "https://api.hubapi.com/email/public/v1/subscriptions";
16
17
        $queryString = build_query_string(['portalId' => $portal_id]);
18
19
        return $this->client->request('get', $endpoint, [], $queryString);
20
    }
21
22
    /**
23
     * View subscriptions timeline for a portal.
24
     *
25
     * @param array $params Optional parameters
26
     * @return \SevenShores\Hubspot\Http\Response
27
     */
28
    function subscriptionsTimeline($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...
29
    {
30
        $endpoint = "https://api.hubapi.com/email/public/v1/subscriptions/timeline";
31
32
        $queryString = build_query_string($params);
33
34
        return $this->client->request('get', $endpoint, [], $queryString);
35
    }
36
37
    /**
38
     * Get email subscription status for an email address.
39
     *
40
     * @param int    $portal_id
41
     * @param string $email
42
     * @return \SevenShores\Hubspot\Http\Response
43
     */
44
    function subscriptionStatus($portal_id, $email)
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/email/public/v1/subscriptions/{$email}";
47
48
        $queryString = build_query_string(['portalId' => $portal_id]);
49
50
        return $this->client->request('get', $endpoint, [], $queryString);
51
    }
52
53
    /**
54
     * Update email subscription status for an email address.
55
     *
56
     * @param int    $portal_id
57
     * @param string $email
58
     * @param array  $params
59
     * @return \SevenShores\Hubspot\Http\Response
60
     */
61
    function updateSubscription($portal_id, $email, $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...
62
    {
63
        $endpoint = "https://api.hubapi.com/email/public/v1/subscriptions/{$email}";
64
65
        $queryString = build_query_string(['portalId' => $portal_id]);
66
        $options['json'] = $params;
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...
67
68
        return $this->client->request('put', $endpoint, $options, $queryString);
69
    }
70
71
}
72