These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * Copyright 2014 Brian Smith <[email protected]>. |
||
5 | * |
||
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
7 | * you may not use this file except in compliance with the License. |
||
8 | * You may obtain a copy of the License at |
||
9 | * |
||
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
11 | * |
||
12 | * Unless required by applicable law or agreed to in writing, software |
||
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
15 | * See the License for the specific language governing permissions and |
||
16 | * limitations under the License. |
||
17 | */ |
||
18 | |||
19 | namespace phparia\Api; |
||
20 | |||
21 | use GuzzleHttp\Exception\RequestException; |
||
22 | use phparia\Client\AriClientAware; |
||
23 | use phparia\Exception\ConflictException; |
||
24 | use phparia\Exception\NotFoundException; |
||
25 | use phparia\Resources\DeviceState; |
||
26 | |||
27 | /** |
||
28 | * DeviceStates API |
||
29 | * |
||
30 | * @author Brian Smith <[email protected]> |
||
31 | */ |
||
32 | class DeviceStates extends AriClientAware |
||
33 | { |
||
34 | const DEVICE_STATE_UNKNOWN = 'UNKNOWN'; |
||
35 | const DEVICE_STATE_NOT_INUSE = 'NOT_INUSE'; |
||
36 | const DEVICE_STATE_INUSE = 'INUSE'; |
||
37 | const DEVICE_STATE_BUSY = 'BUSY'; |
||
38 | const DEVICE_STATE_INVALID = 'INVALID'; |
||
39 | const DEVICE_STATE_UNAVAILABLE = 'UNAVAILABLE'; |
||
40 | const DEVICE_STATE_RINGING = 'RINGING'; |
||
41 | const DEVICE_STATE_RINGINUSE = 'RINGINUSE'; |
||
42 | const DEVICE_STATE_ONHOLD = 'ONHOLD'; |
||
43 | |||
44 | /** |
||
45 | * List all ARI controlled device states. |
||
46 | * |
||
47 | * @return DeviceState[] |
||
48 | */ |
||
49 | View Code Duplication | public function getDeviceStates() |
|
0 ignored issues
–
show
|
|||
50 | 1 | { |
|
51 | $uri = 'deviceStates'; |
||
52 | 1 | $response = $this->client->getEndpoint()->get($uri); |
|
53 | 1 | ||
54 | $deviceStates = []; |
||
55 | 1 | foreach (\GuzzleHttp\json_decode($response->getBody()) as $deviceState) { |
|
56 | 1 | $deviceStates[] = new DeviceState($this->client, $deviceState); |
|
57 | 1 | } |
|
58 | 1 | ||
59 | return $deviceStates; |
||
60 | 1 | } |
|
61 | |||
62 | /** |
||
63 | * Retrieve the current state of a device. |
||
64 | * |
||
65 | * @param string $deviceName |
||
66 | * @return DeviceState |
||
67 | */ |
||
68 | View Code Duplication | public function getDeviceState($deviceName) |
|
0 ignored issues
–
show
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 | 3 | { |
|
70 | $uri = "deviceStates/$deviceName"; |
||
71 | 3 | $response = $this->client->getEndpoint()->get($uri); |
|
72 | 3 | ||
73 | return new DeviceState($this->client, \GuzzleHttp\json_decode($response->getBody())); |
||
74 | 3 | } |
|
75 | |||
76 | /** |
||
77 | * Change the state of a device controlled by ARI. (Note - implicitly creates the device state). |
||
78 | * |
||
79 | * @param string $deviceName Name of the device |
||
80 | * @param string $deviceState (required) Device state value |
||
81 | * @throws ConflictException |
||
82 | * @throws NotFoundException |
||
83 | */ |
||
84 | public function updateDeviceState($deviceName, $deviceState) |
||
85 | 2 | { |
|
86 | $uri = "deviceStates/$deviceName"; |
||
87 | 2 | try { |
|
88 | $this->client->getEndpoint()->put($uri, [ |
||
89 | 2 | 'form_params' => [ |
|
90 | 2 | 'deviceState' => $deviceState, |
|
91 | 2 | ] |
|
92 | 2 | ]); |
|
93 | } catch (RequestException $e) { |
||
94 | 1 | $this->processRequestException($e); |
|
95 | 1 | } |
|
96 | } |
||
97 | 1 | ||
98 | /** |
||
99 | * Destroy a device-state controlled by ARI. |
||
100 | * |
||
101 | * @param string $deviceName Name of the device |
||
102 | * @throws ConflictException |
||
103 | * @throws NotFoundException |
||
104 | */ |
||
105 | public function deleteDeviceState($deviceName) |
||
106 | 2 | { |
|
107 | $uri = "deviceStates/$deviceName"; |
||
108 | 2 | try { |
|
109 | $this->client->getEndpoint()->delete($uri); |
||
110 | 2 | } catch (RequestException $e) { |
|
111 | 2 | $this->processRequestException($e); |
|
112 | } |
||
113 | 1 | } |
|
114 | } |
||
115 |
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.