Completed
Pull Request — master (#73)
by
unknown
05:13
created

Engagements::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 4
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class Engagements extends Resource
6
{
7
    /**
8
     * @param array $engagement Array of engagement engagement.
9
     * @param array $associations Array of engagement associations.
10
     * @param array $metadata Array of engagement metadata.
11
     * @param array $attachments Array of engagement attachments.
12
     * @return \SevenShores\Hubspot\Http\Response
13
     */
14
    function create($engagement, $associations, $metadata, $attachments = array())
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...
15
    {
16
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements";
17
18
        $options['json'] = [
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...
19
            'engagement' => $engagement,
20
            'associations' => $associations,
21
            'metadata' => $metadata,
22
            'attachments' => $attachments
23
        ];
24
25
        return $this->client->request('post', $endpoint, $options);
26
    }
27
28
    /**
29
     * @param int   $id         The engagement id.
30
     * @param array $engagement The engagement engagement to update.
31
     * @param array $metadata The engagement metadata to update.
32
     * @return \SevenShores\Hubspot\Http\Response
33
     */
34 View Code Duplication
    function update($id, $engagement, $metadata)
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...
35
    {
36
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
37
38
        $options['json'] = [
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...
39
            'engagement' => $engagement,
40
            'metadata' => $metadata,
41
        ];
42
43
        return $this->client->request('put', $endpoint, $options);
44
    }
45
46
    /**
47
     * @param int $id
48
     * @return \SevenShores\Hubspot\Http\Response
49
     */
50
    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...
51
    {
52
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
53
54
        return $this->client->request('delete', $endpoint);
55
    }
56
57
    /**
58
     * @param int $id
59
     * @return \SevenShores\Hubspot\Http\Response
60
     */
61
    function get($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...
62
    {
63
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}";
64
65
        return $this->client->request('get', $endpoint);
66
    }
67
68
    /**
69
     * Returns all engagements.
70
     *
71
     * @param array $params Array of optional parameters ['limit', 'offset']
72
     *
73
     * @see http://developers.hubspot.com/docs/methods/engagements/get-all-engagements
74
     *
75
     * @return \SevenShores\Hubspot\Http\Response
76
     */
77
    public function all($params = [])
78
    {
79
        $endpoint = 'https://api.hubapi.com/engagements/v1/engagements/paged';
80
81
        $queryString = build_query_string($params);
82
83
        return $this->client->request('get', $endpoint, [], $queryString);
84
    }
85
86
    /**
87
     * @param int $id
88
     * @param string $object_type
89
     * @param int $object_id
90
     * @return \SevenShores\Hubspot\Http\Response
91
     **/
92
    function associate($id, $object_type, $object_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...
93
    {
94
        $endpoint = "https://api.hubapi.com/engagements/v1/engagements/{$id}/associations/{$object_type}/{$object_id}";
95
96
        return $this->client->request('put', $endpoint);
97
    }
98
}
99