Completed
Push — master ( 70f1e1...18755d )
by Ryan
01:35
created

CalendarEvents::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class CalendarEvents extends Resource
6
{
7
    /**
8
     * @param array $properties
9
     *
10
     * @return \SevenShores\Hubspot\Http\Response
11
     */
12
    public function createTask($properties)
13
    {
14
        $endpoint = 'https://api.hubapi.com/calendar/v1/events/task';
15
        $options['json'] = $properties;
16
17
        return $this->client->request('post', $endpoint, $options);
18
    }
19
20
    /**
21
     * @param int   $id         The task id.
22
     * @param array $properties The task properties to update.
23
     *
24
     * @return \SevenShores\Hubspot\Http\Response
25
     */
26
    public function updateTask($id, $properties)
27
    {
28
        $endpoint = "https://api.hubapi.com/calendar/v1/events/task/{$id}";
29
30
        $options['json'] = $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...
31
32
        return $this->client->request('put', $endpoint, $options);
33
    }
34
35
    /**
36
     * @param int $id
37
     *
38
     * @return \SevenShores\Hubspot\Http\Response
39
     */
40
    public function getTaskById($id)
41
    {
42
        $endpoint = "https://api.hubapi.com/calendar/v1/events/task/{$id}";
43
44
        return $this->client->request('get', $endpoint);
45
    }
46
47
    /**
48
     * @param int $id
49
     * @return \SevenShores\Hubspot\Http\Response
50
     */
51
    public function deleteTask($id)
52
    {
53
        $endpoint = "https://api.hubapi.com/calendar/v1/events/task/{$id}";
54
55
        return $this->client->request('delete', $endpoint);
56
    }
57
58
    /**
59
     * Get an aggregation for all calendar event types.
60
     *
61
     *
62
     * @see https://developers.hubspot.com/docs/methods/calendar/list-events
63
     *
64
     * @param int $startDate    The beginning value of the query range, in UTC, in milliseconds
65
     * @param int $endDate      The end value of the query range, in UTC, in milliseconds
66
     * @param array $params     Array of optional parameters:
67
     *                          limit, type, campaignGuid, contentCategory, includeNoCampaigns
68
     *
69
     * @return \SevenShores\Hubspot\Http\Response
70
     */
71 View Code Duplication
    public function all($startDate, $endDate, $params = [])
72
    {
73
        $endpoint = "https://api.hubapi.com/calendar/v1/events";
74
        $params = array_merge(compact('startDate', 'endDate'), $params);
75
76
        $queryString = build_query_string($params);
77
78
        return $this->client->request('get', $endpoint, [], $queryString);
79
    }
80
81
    /**
82
     * Retrieve task events for Calendar.
83
     * A shortcut of the standard events call for finer-grained control.
84
     *
85
     * @see https://developers.hubspot.com/docs/methods/calendar/list-tasks
86
     *
87
     * @param int $startDate    The beginning value of the query range, in UTC, in milliseconds
88
     * @param int $endDate      The end value of the query range, in UTC, in milliseconds
89
     * @param array $params     Array of optional parameters:
90
     *                          limit, campaignGuid, includeNoCampaigns
91
     *
92
     * @return \SevenShores\Hubspot\Http\Response
93
     */
94 View Code Duplication
    public function allTasks($startDate, $endDate, $params = [])
95
    {
96
        $endpoint = "https://api.hubapi.com/calendar/v1/events/task";
97
        $params = array_merge(compact('startDate', 'endDate'), $params);
98
99
        $queryString = build_query_string($params);
100
101
        return $this->client->request('get', $endpoint, [], $queryString);
102
    }
103
104
    /**
105
     * Retrieve social events for Calendar.
106
     * A shortcut of the standard events call for finer-grained control.
107
     *
108
     * @see https://developers.hubspot.com/docs/methods/calendar/list-social-events
109
     *
110
     * @param int $startDate    The beginning value of the query range, in UTC, in milliseconds
111
     * @param int $endDate      The end value of the query range, in UTC, in milliseconds
112
     * @param array $params     Array of optional parameters:
113
     *                          limit, offset, campaignGuid, includeNoCampaigns
114
     *
115
     * @return \SevenShores\Hubspot\Http\Response
116
     */
117 View Code Duplication
    public function allSocialEvents($startDate, $endDate, $params = [])
118
    {
119
        $endpoint = "https://api.hubapi.com/calendar/v1/events/social";
120
        $params = array_merge(compact('startDate', 'endDate'), $params);
121
122
        $queryString = build_query_string($params);
123
124
        return $this->client->request('get', $endpoint, [], $queryString);
125
    }
126
127
    /**
128
     * List content events.
129
     * Get events from the calendar.
130
     *
131
     * @see https://developers.hubspot.com/docs/methods/calendar/list-content-events
132
     *
133
     * @param int $startDate    The beginning value of the query range, in UTC, in milliseconds
134
     * @param int $endDate      The end value of the query range, in UTC, in milliseconds
135
     * @param array $params     Array of optional parameters:
136
     *                          limit, offset, contentCategory, campaignGuid, includeNoCampaigns
137
     *
138
     * @return \SevenShores\Hubspot\Http\Response
139
     */
140 View Code Duplication
    public function allContentEvents($startDate, $endDate, $params = [])
141
    {
142
        $endpoint = "https://api.hubapi.com/calendar/v1/events/content";
143
        $params = array_merge(compact('startDate', 'endDate'), $params);
144
145
        $queryString = build_query_string($params);
146
147
        return $this->client->request('get', $endpoint, [], $queryString);
148
    }
149
}
150