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

GoalManager::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 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 6
    public function query($options = [])
29
    {
30 6
        $url = '/goals';
31 6
        $url .= isset($options['limit_by_site']) ? "&limit_by_site={$options['limit_by_site']}" : '';
32
33
        // Now make the request.
34 6
        $request = new Request('GET', $url);
35 6
        $data = $this->client->getResponseJson($request);
36
37
        // Get them as Goal objects
38 3
        $goals = [];
39 3
        foreach ($data as $dataItem) {
40 5
            $goals[] = new Goal($dataItem);
41 2
        }
42
43 3
        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 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...
58
      $id
59
    ) {
60 6
        $url = "/goals/{$id}";
61
62
        // Now make the request.
63 6
        $request = new Request('GET', $url);
64 6
        $data = $this->client->getResponseJson($request);
65
66 3
        return new Goal($data);
67
    }
68
69
    /**
70
     * Add a goal.
71
     *
72
     * @see http://docs.decision-api.acquia.com/#goals_post
73
     *
74
     * @param \Acquia\LiftClient\Entity\Goal $goal
75
     *
76
     * @throws \GuzzleHttp\Exception\RequestException
77
     *
78
     * @return \Acquia\LiftClient\Entity\Goal
79
     */
80 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...
81
      Goal $goal
82
    ) {
83 6
        $body = $goal->json();
84 6
        $url = '/goals';
85 6
        $request = new Request('POST', $url, [], $body);
86 6
        $data = $this->client->getResponseJson($request);
87
88 3
        return new Goal($data);
89
    }
90
91
    /**
92
     * Deletes a goal by ID.
93
     *
94
     * @see http://docs.decision-api.acquia.com/#goals__goal_id__delete
95
     *
96
     * @param string $id
97
     *
98
     * @throws \GuzzleHttp\Exception\RequestException
99
     *
100
     * @return bool
101
     */
102 6
    public function delete(
103
      $id
104
    ) {
105 6
        $url = "/goals/{$id}";
106 6
        $this->client->delete($url);
107
108 3
        return true;
109
    }
110
}
111