Completed
Pull Request — master (#136)
by
unknown
09:15 queued 04:30
created

Workflows::logEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Workflows extends Resource
6
{
7
    /**
8
     * Get all workflows.
9
     *
10
     * @return \SevenShores\Hubspot\Http\Response
11
     */
12
    public function all()
13
    {
14
        $endpoint = 'https://api.hubapi.com/automation/v3/workflows';
15
16
        return $this->client->request('get', $endpoint);
17
    }
18
19
    /**
20
     * Get a specific workflow.
21
     *
22
     * @param int $id
23
     *
24
     * @return \SevenShores\Hubspot\Http\Response
25
     */
26
    public function getById($id)
27
    {
28
        $endpoint = "https://api.hubapi.com/automation/v3/workflows/{$id}";
29
30
        return $this->client->request('get', $endpoint);
31
    }
32
33
    /**
34
     * Enroll a contact in a workflow.
35
     *
36
     * @param int    $workflow_id
37
     * @param string $email
38
     *
39
     * @return \SevenShores\Hubspot\Http\Response
40
     */
41
    public function enrollContact($workflow_id, $email)
42
    {
43
        $endpoint = "https://api.hubapi.com/automation/v2/workflows/{$workflow_id}/enrollments/contacts/{$email}";
44
45
        return $this->client->request('post', $endpoint);
46
    }
47
48
    /**
49
     * Unenroll a contact from a workflow.
50
     *
51
     * @param int    $workflow_id
52
     * @param string $email
53
     *
54
     * @return \SevenShores\Hubspot\Http\Response
55
     */
56
    public function unenrollContact($workflow_id, $email)
57
    {
58
        $endpoint = "https://api.hubapi.com/automation/v2/workflows/{$workflow_id}/enrollments/contacts/{$email}";
59
60
        return $this->client->request('delete', $endpoint);
61
    }
62
63
    /**
64
     * Create a new workflow.
65
     *
66
     * @param array $workflow The workflow properties
67
     *
68
     * @return \SevenShores\Hubspot\Http\Response
69
     */
70
    public function create($workflow)
71
    {
72
        $endpoint = 'https://api.hubapi.com/automation/v3/workflows';
73
74
        $options['json'] = $workflow;
75
76
        return $this->client->request('post', $endpoint, $options);
77
    }
78
79
    /**
80
     * Delete a workflow.
81
     *
82
     * @param int $id
83
     *
84
     * @return \SevenShores\Hubspot\Http\Response
85
     */
86
    public function delete($id)
87
    {
88
        $endpoint = "https://api.hubapi.com/automation/v3/workflows/{$id}";
89
90
        return $this->client->request('delete', $endpoint, []);
91
    }
92
93
    /**
94
     * Get current enrollments for a contact.
95
     *
96
     * @param int $contact_id
97
     *
98
     * @return \SevenShores\Hubspot\Http\Response
99
     */
100
    public function enrollmentsForContact($contact_id)
101
    {
102
        $endpoint = "https://api.hubapi.com/automation/v2/workflows/enrollments/contacts/{$contact_id}";
103
104
        return $this->client->request('get', $endpoint);
105
    }
106
107
    /**
108
     * Get a history of events for a specific workflow, filtered for a
109
     * specific contact and/or event type(s).
110
     *
111
     * @param int   $workflow_id
112
     * @param array $filter
113
     * @param array $params      Optional parameters.
114
     *
115
     * @return \SevenShores\Hubspot\Http\Response
116
     */
117 View Code Duplication
    public function logEvents($workflow_id, $filter, $params = [])
118
    {
119
        $endpoint = "https://api.hubapi.com/automation/v3/logevents/workflows/{$workflow_id}/filter";
120
121
        $options['json'] = $filter;
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...
122
123
        $queryString = build_query_string($params);
124
125
        return $this->client->request('put', $endpoint, $options, $queryString);
126
    }
127
}
128