Completed
Pull Request — master (#4)
by Nick
05:39
created

GoalManager::query()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

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