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

SlotManager::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Acquia\LiftClient\Manager;
4
5
use Acquia\LiftClient\Entity\Slot;
6
use GuzzleHttp\Psr7\Request;
7
8
class SlotManager extends ManagerBase
9
{
10
11
    /**
12
     * Get a list of slots.
13
     *
14
     * Example of how to structure the $options parameter:
15
     * <code>
16
     * $options = [
17
     *     'visible_on_page'  => 'http://localhost/blog/*',
18
     *     'status' => 'enabled',
19
     * ];
20
     * </code>
21
     *
22
     * @see http://docs.decision-api.acquia.com/#slots_get
23
     *
24
     * @param array $options
25
     *
26
     * @return \Acquia\LiftClient\Entity\Slot[]
27
     *
28
     * @throws \GuzzleHttp\Exception\RequestException
29
     */
30 6
    public function query($options = [])
31
    {
32
        $variables = $options + [
33 6
            'limit' => 1000,
34 4
            'start' => 0,
35 4
          ];
36
37 6
        $url = "/slots";
38 6
        $url .= isset($variables['visible_on_page']) ? "&visible_on_page={$variables['visible_on_page']}" : '';
39 6
        $url .= isset($variables['status']) ? "&status={$variables['status']}" : '';
40
41
        // Now make the request.
42 6
        $request = new Request('GET', $url);
43 6
        $data = $this->client->getResponseJson($request);
44
45
        // Get them as Slot objects
46 3
        $slots = [];
47 3
        foreach ($data as $dataItem) {
48 3
            $slots[] = new Slot($dataItem);
49 2
        }
50
51 3
        return $slots;
52
    }
53
54
55
    /**
56
     * Get a specific slot
57
     *
58
     * Example of how to structure the $options parameter:
59
     *
60
     * @see http://docs.decision-api.acquia.com/#slots__slotId__get
61
     *
62
     * @param array $options
0 ignored issues
show
Bug introduced by
There is no parameter named $options. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
63
     *
64
     * @return \Acquia\LiftClient\Entity\Slot
65
     *
66
     * @throws \GuzzleHttp\Exception\RequestException
67
     */
68 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...
69
      $slotId
70
    ) {
71 6
        $url = "/slots/{$slotId}";
72
73
        // Now make the request.
74 6
        $request = new Request('GET', $url);
75 6
        $data = $this->client->getResponseJson($request);
76
77 3
        return new Slot($data);
78
    }
79
80
    /**
81
     * Add a slot
82
     *
83
     * @param \Acquia\LiftClient\Entity\Slot $slot
84
     *
85
     * @return \Acquia\LiftClient\Entity\Slot
86
     *
87
     * @throws \GuzzleHttp\Exception\RequestException
88
     */
89 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...
90
      Slot $slot
91
    ) {
92 6
        $body = $slot->json();
93 6
        $url = "/slots";
94 6
        $request = new Request('POST', $url, [], $body);
95 6
        $data = $this->client->getResponseJson($request);
96
97 3
        return new Slot($data);
98
    }
99
100
    /**
101
     * Deletes a slot by ID.
102
     *
103
     * @param string $id
104
     *
105
     * @return bool
106
     *   returns TRUE if successful.
107
     *
108
     * @throws \GuzzleHttp\Exception\RequestException
109
     */
110 6
    public function delete(
111
      $id
112
    ) {
113 6
        $url = "/slots/{$id}";
114 6
        $this->client->delete($url);
115
116 3
        return true;
117
    }
118
}
119