Completed
Push — master ( 9f4de8...df05ba )
by Ryan
03:39
created

DealProperties::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot\Resources;
4
5
class DealProperties extends Resource
6
{
7
8
    /**
9
     * Get a Deal Property.
10
     *
11
     * Returns a JSON object representing the definition for a given deal property.
12
     *
13
     * @see http://developers.hubspot.com/docs/methods/deals/get_deal_property
14
     *
15
     * @param string $name The name of the property.
16
     * @return \SevenShores\Hubspot\Http\Response
17
     */
18
    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...
19
    {
20
        $endpoint = "https://api.hubapi.com/deals/v1/properties/named/{$name}";
21
22
        return $this->client->request('get', $endpoint);
23
    }
24
25
    /**
26
     * Create a deal property.
27
     *
28
     * Create a property on every deal object to store a specific piece of data. In the example below,
29
     * we want to store an invoice number on a separate field on deals.
30
     *
31
     * @see https://developers.hubspot.com/docs/methods/deals/create_deal_property
32
     *
33
     * @param array $property
34
     * @return \SevenShores\Hubspot\Http\Response
35
     */
36
    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...
37
    {
38
        $endpoint = "https://api.hubapi.com/properties/v1/deals/properties/";
39
40
        $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...
41
42
        return $this->client->request('post', $endpoint, $options);
43
    }
44
45
    /**
46
     * Update a deal property.
47
     *
48
     * Update a specified deal property.
49
     *
50
     * @see http://developers.hubspot.com/docs/methods/deals/update_deal_property
51
     *
52
     * @param string $name
53
     * @param array  $property
54
     * @return \SevenShores\Hubspot\Http\Response
55
     */
56 View Code Duplication
    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...
57
    {
58
        $endpoint = "https://api.hubapi.com/deals/v1/properties/named/{$name}";
59
60
        $property['name'] = $name;
61
        $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...
62
63
        return $this->client->request('put', $endpoint, $options);
64
    }
65
66
}
67