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 Pest_BadRequest; |
||
22 | use Pest_Conflict; |
||
23 | use Pest_NotFound; |
||
24 | use phparia\Client\AriClientAware; |
||
25 | use phparia\Exception\ConflictException; |
||
26 | use phparia\Exception\InvalidParameterException; |
||
27 | use phparia\Exception\NotFoundException; |
||
28 | use phparia\Resources\Playback; |
||
29 | |||
30 | /** |
||
31 | * Playbacks API |
||
32 | * |
||
33 | * @author Brian Smith <[email protected]> |
||
34 | */ |
||
35 | class Playbacks extends AriClientAware |
||
36 | { |
||
37 | const OPERATION_PAUSE = 'pause'; |
||
38 | const OPERATION_UNPAUSE = 'unpause'; |
||
39 | const OPERATION_REVERSE = 'reverse'; |
||
40 | const OPERATION_FORWARD = 'forward'; |
||
41 | const OPERATION_RESTART = 'restart'; |
||
42 | |||
43 | /** |
||
44 | * Get a playback's details. |
||
45 | * |
||
46 | * @param string $playbackId Playback's id |
||
47 | * @return Playback |
||
48 | * @throws NotFoundException |
||
49 | */ |
||
50 | 4 | public function getPlayback($playbackId) |
|
51 | { |
||
52 | 4 | $uri = "/playbacks/$playbackId"; |
|
53 | try { |
||
54 | 4 | $response = $this->client->getEndpoint()->get($uri); |
|
55 | 4 | } catch (Pest_NotFound $e) { // Playback not found |
|
56 | 2 | throw new NotFoundException($e); |
|
57 | } |
||
58 | |||
59 | 3 | return new Playback($this->client, $response); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Stop a playback. |
||
64 | * |
||
65 | * @param string $playbackId Playback's id |
||
66 | * @throws NotFoundException |
||
67 | */ |
||
68 | 2 | View Code Duplication | public function stopPlayback($playbackId) |
0 ignored issues
–
show
|
|||
69 | { |
||
70 | 2 | $uri = "/playbacks/$playbackId"; |
|
71 | try { |
||
72 | 2 | $this->client->getEndpoint()->delete($uri); |
|
73 | 2 | } catch (Pest_NotFound $e) { // Playback not found |
|
74 | throw new NotFoundException($e); |
||
75 | } |
||
76 | 2 | } |
|
77 | |||
78 | /** |
||
79 | * Control a playback. |
||
80 | * |
||
81 | * @param string $playbackId Playback's id |
||
82 | * @param string $operation (required) Operation to perform on the playback. Allowed values: restart, pause, unpause, reverse, forward. |
||
83 | * @throws ConflictException |
||
84 | * @throws InvalidParameterException |
||
85 | * @throws NotFoundException |
||
86 | */ |
||
87 | 1 | View Code Duplication | public function controlPlayback($playbackId, $operation) |
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...
|
|||
88 | { |
||
89 | 1 | $uri = "/playbacks/$playbackId/control"; |
|
90 | try { |
||
91 | 1 | $this->client->getEndpoint()->post($uri, array( |
|
92 | 1 | 'operation' => $operation, |
|
93 | 1 | )); |
|
94 | 1 | } catch (Pest_BadRequest $e) { |
|
95 | throw new InvalidParameterException($e); |
||
96 | } catch (Pest_NotFound $e) { |
||
97 | throw new NotFoundException($e); |
||
98 | } catch (Pest_Conflict $e) { |
||
99 | throw new ConflictException($e); |
||
100 | } |
||
101 | 1 | } |
|
102 | |||
103 | } |
||
104 |
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.