DealPipelines::getPipeline()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
namespace SevenShores\Hubspot\Resources;
3
4
class DealPipelines extends Resource {
5
6
    public function getAllPipelines()
7
    {
8
        $endpoint = 'https://api.hubapi.com/deals/v1/pipelines';
9
10
        return $this->client->request('get', $endpoint);
11
12
    }
13
14
    public function getPipeline($id)
15
    {
16
        $endpoint = "https://api.hubapi.com/deals/v1/pipelines/{$id}";
17
18
        return $this->client->request('get', $endpoint);
19
    }
20
21
    public function create(array $pipeline)
22
    {
23
        $endpoint = "https://api.hubapi.com/deals/v1/pipelines";
24
25
        $options['json'] = $pipeline;
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...
26
27
        return $this->client->request('post', $endpoint, $options);
28
    }
29
30
    public function update($id, array $pipeline)
31
    {
32
        $endpoint = "https://api.hubapi.com/deals/v1/pipelines/{$id}";
33
34
        $options['json'] = $pipeline;
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...
35
36
        return $this->client->request('put', $endpoint, $options);
37
    }
38
39
    public function delete($id)
40
    {
41
        $endpoint = "https://api.hubapi.com/deals/v1/pipelines/{$id}";
42
43
        return $this->client->request('delete', $endpoint);
44
    }
45
}