Completed
Push — master ( 7b6a9e...621ea2 )
by Nick
15:23
created

GoalManager::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Acquia\LiftClient\Manager;
4
5
use Acquia\LiftClient\Entity\Goal;
6
use GuzzleHttp\Psr7\Request;
7
8
class GoalManager extends ManagerBase
9
{
10
    /**
11
     * Get a list of Goals.
12
     *
13
     * Example of how to structure the $options parameter:
14
     * <code>
15
     * $options = [
16
     *     'limit_by_site'  => 'my-site-id'
17
     * ];
18
     * </code>
19
     *
20
     * @see http://docs.decision-api.acquia.com/#goals_get
21
     *
22
     * @param array $options
23
     *
24
     * @throws \GuzzleHttp\Exception\RequestException
25
     *
26
     * @return \Acquia\LiftClient\Entity\Goal[]
27
     */
28
    public function query($options = [])
29
    {
30
        $url = '/goals';
31
        $url .= isset($options['limit_by_site']) ? "&limit_by_site={$options['limit_by_site']}" : '';
32
33
        // Now make the request.
34
        $request = new Request('GET', $url);
35
        $data = $this->client->getResponseJson($request);
36
37
        // Get them as Goal objects
38
        $goals = [];
39
        foreach ($data as $dataItem) {
40
            $goals[] = new Goal($dataItem);
41
        }
42
43
        return $goals;
44
    }
45
46
    /**
47
     * Get a specific goal.
48
     *
49
     * @see http://docs.decision-api.acquia.com/#goals__goal_id__get
50
     *
51
     * @param array $id
52
     *
53
     * @throws \GuzzleHttp\Exception\RequestException
54
     *
55
     * @return \Acquia\LiftClient\Entity\Goal
56
     */
57 View Code Duplication
    public function get($id) {
1 ignored issue
show
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...
58
        $url = "/goals/{$id}";
59
60
        // Now make the request.
61
        $request = new Request('GET', $url);
62
        $data = $this->client->getResponseJson($request);
63
64
        return new Goal($data);
65
    }
66
67
    /**
68
     * Add a goal.
69
     *
70
     * @see http://docs.decision-api.acquia.com/#goals_post
71
     *
72
     * @param \Acquia\LiftClient\Entity\Goal $goal
73
     *
74
     * @throws \GuzzleHttp\Exception\RequestException
75
     *
76
     * @return \Acquia\LiftClient\Entity\Goal
77
     */
78 View Code Duplication
    public function add(Goal $goal) {
1 ignored issue
show
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...
79
        $body = $goal->json();
80
        $url = '/goals';
81
        $request = new Request('POST', $url, [], $body);
82
        $data = $this->client->getResponseJson($request);
83
84
        return new Goal($data);
85
    }
86
87
    /**
88
     * Deletes a goal by ID.
89
     *
90
     * @see http://docs.decision-api.acquia.com/#goals__goal_id__delete
91
     *
92
     * @param string $id
93
     *
94
     * @throws \GuzzleHttp\Exception\RequestException
95
     *
96
     * @return bool
97
     */
98
    public function delete($id) {
99
        $url = "/goals/{$id}";
100
        $this->client->delete($url);
101
102
        return true;
103
    }
104
}
105