Completed
Push — master ( 68d8d1...ccbd05 )
by Brian
02:42
created

Channels   C

Complexity

Total Complexity 63

Size/Duplication

Total Lines 567
Duplicated Lines 23.63 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 16.74%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 63
c 6
b 0
f 2
lcom 1
cbo 9
dl 134
loc 567
ccs 37
cts 221
cp 0.1674
rs 5.8893

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getChannels() 0 12 2
A getChannel() 0 11 2
B createChannelWithId() 0 35 2
A deleteChannel() 9 9 2
A hangup() 0 8 2
A continueDialplan() 0 15 3
A answer() 11 11 3
A startRinging() 11 11 3
A stopRinging() 11 11 3
A sendDtmf() 0 19 4
A mute() 0 13 3
A unmute() 11 11 3
A hold() 11 11 3
A unhold() 11 11 3
A startSilence() 11 11 3
A stopSilence() 11 11 3
B getVariable() 0 20 5
A setVariable() 0 18 4
A startSnoop() 19 19 3
A startSnoopWithId() 18 18 3
A getType() 0 4 1
B createChannel() 0 38 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Channels often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Channels, and based on these observations, apply Extract Interface, too.

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 Pest_ServerError;
25
use phparia\Resources\Channel;
26
use phparia\Resources\Variable;
27
use phparia\Exception\ConflictException;
28
use phparia\Exception\InvalidParameterException;
29
use phparia\Exception\NotFoundException;
30
use phparia\Exception\ServerException;
31
32
/**
33
 * Channels API
34
 *
35
 * @author Brian Smith <[email protected]>
36
 */
37
class Channels extends MediaBase
38
{
39
    const AST_STATE_DOWN = 'Down'; // Channel is down and available
40
    const AST_STATE_RESERVED = 'Rsrvd'; // Channel is down, but reserved
41
    const AST_STATE_OFFHOOK = 'OffHook'; // Channel is off hook
42
    const AST_STATE_DIALING = 'Dialing'; // Digits (or equivalent) have been dialed
43
    const AST_STATE_RING = 'Ring'; // Line is ringing
44
    const AST_STATE_RINGING = 'Ringing'; // Remote end is ringing
45
    const AST_STATE_UP = 'Up'; // Line is up
46
    const AST_STATE_BUSY = 'Busy'; // Line is busy
47
    const AST_STATE_DIALING_OFFHOOK = 'Dialing Offhook'; // Digits (or equivalent) have been dialed while offhook
48
    const AST_STATE_PRERING = 'Pre-ring'; // Channel has detected an incoming call and is waiting for ring
49
    const AST_STATE_MUTE = 'Mute'; // Do not transmit voice data
50
    const AST_STATE_UNKNOWN = 'Unknown';
51
52
    /**
53
     * List all active channels in Asterisk.
54
     *
55
     * @return Channel[]
56
     */
57
    public function getChannels()
58
    {
59
        $uri = '/channels';
60
        $response = $this->client->getEndpoint()->get($uri);
61
62
        $channels = [];
63
        foreach ((array)$response as $channel) {
64
            $channels[] = new Channel($this->client, $channel);
65
        }
66
67
        return $channels;
68
    }
69
70
    /**
71
     * Create a new channel (originate). The new channel is created immediately and a snapshot of it
72
     * returned. If a Stasis application is provided it will be automatically subscribed to the originated
73
     * channel for further events and updates.
74
     *
75
     * @param string $endpoint (required) Endpoint to call.
76
     * @param string $extension The extension to dial after the endpoint answers
77
     * @param string $context The context to dial after the endpoint answers. If omitted, uses 'default'
78
     * @param int $priority The priority to dial after the endpoint answers. If omitted, uses 1
79
     * @param string $label Asterisk 13+ The label to dial after the endpoint answers. Will supersede 'priority' if provided. Mutually exclusive with 'app'.
80
     * @param string $app The application that is subscribed to the originated channel. When the channel is answered, it will be passed to this Stasis application. Mutually exclusive with 'context', 'extension', 'priority', and 'label'.
81
     * @param string $appArgs The application arguments to pass to the Stasis application.
82
     * @param string $callerId CallerID to use when dialing the endpoint or extension.
83
     * @param int $timeout (default 30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
84
     * @param string $channelId The unique id to assign the channel on creation.
85
     * @param string $otherChannelId The unique id to assign the second channel when using local channels.
86
     * @param array $variables The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
87
     * @return Channel
88
     * @throws InvalidParameterException
89
     * @throws ServerException
90
     */
91 38
    public function createChannel(
92
        $endpoint,
93
        $extension = null,
94
        $context = null,
95
        $priority = null,
96
        $label = null,
97
        $app = null,
98
        $appArgs = null,
99
        $callerId = null,
100
        $timeout = null,
101
        $channelId = null,
102
        $otherChannelId = null,
103
        $variables = array()
104
    ) {
105 38
        $uri = '/channels';
106
        try {
107 38
            $response = $this->client->getEndpoint()->post($uri, array(
108 38
                'endpoint' => $endpoint,
109 38
                'extension' => $extension,
110 38
                'context' => $context,
111 38
                'priority' => $priority,
112 38
                'label' => $label,
113 38
                'app' => $app,
114 38
                'appArgs' => $appArgs,
115 38
                'callerId' => $callerId,
116 38
                'timeout' => $timeout,
117 38
                'channelId' => $channelId,
118 38
                'otherChannelId' => $otherChannelId,
119 38
                'variables' => array_map('strval', $variables),
120 38
            ));
121 38
        } catch (Pest_BadRequest $e) { // Invalid parameters for originating a channel.
122
            throw new InvalidParameterException($e);
123 1
        } catch (Pest_ServerError $e) {
124 1
            throw new ServerException($e); // Couldn't create the channel.
125
        }
126
127 37
        return new Channel($this->client, $response);
128
    }
129
130
    /**
131
     * Channel details.
132
     *
133
     * @param string $channelId
134
     * @return Channel
135
     * @throws NotFoundException
136
     */
137
    public function getChannel($channelId)
138
    {
139
        $uri = "/channels/$channelId";
140
        try {
141
            $response = $this->client->getEndpoint()->get($uri);
142
        } catch (Pest_NotFound $e) { // Channel not found
143
            throw new NotFoundException($e);
144
        }
145
146
        return new Channel($this->client, $response);
147
    }
148
149
    /**
150
     * Create a new channel (originate). The new channel is created immediately and a snapshot of it
151
     * returned. If a Stasis application is provided it will be automatically subscribed to the originated
152
     * channel for further events and updates.
153
     *
154
     * @param string $endpoint (required) Endpoint to call.
155
     * @param string $extension The extension to dial after the endpoint answers
156
     * @param string $context The context to dial after the endpoint answers. If omitted, uses 'default'
157
     * @param int $priority The priority to dial after the endpoint answers. If omitted, uses 1
158
     * @param string $label Asterisk 13+ The label to dial after the endpoint answers. Will supersede 'priority' if provided. Mutually exclusive with 'app'.
159
     * @param string $app The application that is subscribed to the originated channel, and passed to the Stasis application.
160
     * @param string $appArgs The application arguments to pass to the Stasis application.
161
     * @param string $callerId CallerID to use when dialing the endpoint or extension.
162
     * @param int $timeout (default 30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
163
     * @param string $channelId The unique id to assign the channel on creation.
164
     * @param string $otherChannelId The unique id to assign the second channel when using local channels.
165
     * @param array $variables The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
166
     * @return Channel
167
     * @throws InvalidParameterException
168
     */
169
    public function createChannelWithId(
170
        $endpoint,
171
        $extension = null,
172
        $context = null,
173
        $priority = null,
174
        $label = null,
175
        $app = null,
176
        $appArgs = null,
177
        $callerId = null,
178
        $timeout = null,
179
        $channelId = null,
180
        $otherChannelId = null,
181
        $variables = array()
182
    ) {
183
        $uri = "/channels/$channelId";
184
        try {
185
            $response = $this->client->getEndpoint()->post($uri, array(
186
                'endpoint' => $endpoint,
187
                'extension' => $extension,
188
                'context' => $context,
189
                'priority' => $priority,
190
                'label' => $label,
191
                'app' => $app,
192
                'appArgs' => $appArgs,
193
                'callerId' => $callerId,
194
                'timeout' => $timeout,
195
                'otherChannelId' => $otherChannelId,
196
                'variables' => array_map('strval', $variables),
197
            ));
198
        } catch (Pest_BadRequest $e) { // Invalid parameters for originating a channel.
199
            throw new InvalidParameterException($e);
200
        }
201
202
        return new Channel($this->client, $response);
203
    }
204
205
    /**
206
     * Delete (i.e. hangup) a channel.
207
     *
208
     * @param string $channelId Channel's id
209
     * @throws NotFoundException
210
     */
211 1 View Code Duplication
    public function deleteChannel($channelId)
0 ignored issues
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...
212
    {
213 1
        $uri = "/channels/$channelId";
214
        try {
215 1
            $this->client->getEndpoint()->delete($uri);
216 1
        } catch (Pest_NotFound $e) {
217 1
            throw new NotFoundException($e);
218
        }
219 1
    }
220
221
    /**
222
     * Hangup a channel if it still exists.
223
     *
224
     * @param string $channelId Channel's id
225
     */
226 1
    public function hangup($channelId)
227
    {
228
        try {
229 1
            $this->deleteChannel($channelId);
230 1
        } catch (\Exception $ignore) {
231
            // Don't throw exception if the channel doesn't exist
232
        }
233 1
    }
234
235
    /**
236
     * Exit application; continue execution in the dialplan.
237
     *
238
     * @param string $channelId Channel's id
239
     * @param string $context The context to continue to.
240
     * @param string $extension The extension to continue to.
241
     * @param int $priority The priority to continue to.
242
     * @throws NotFoundException
243
     * @throws ConflictException
244
     */
245
    public function continueDialplan($channelId, $context, $extension, $priority)
246
    {
247
        $uri = "/channels/$channelId/continue";
248
        try {
249
            $this->client->getEndpoint()->post($uri, array(
250
                'context' => $context,
251
                'extension' => $extension,
252
                'priority' => $priority,
253
            ));
254
        } catch (Pest_NotFound $e) {
255
            throw new NotFoundException($e);
256
        } catch (Pest_Conflict $e) {
257
            throw new ConflictException($e);
258
        }
259
    }
260
261
    /**
262
     * Answer a channel.
263
     *
264
     * @param string $channelId Channel's id
265
     * @throws NotFoundException
266
     * @throws ConflictException
267
     */
268 36 View Code Duplication
    public function answer($channelId)
0 ignored issues
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...
269
    {
270 36
        $uri = "/channels/$channelId/answer";
271
        try {
272 36
            $this->client->getEndpoint()->post($uri, array());
273 36
        } catch (Pest_NotFound $e) {
274
            throw new NotFoundException($e);
275
        } catch (Pest_Conflict $e) {
276
            throw new ConflictException($e);
277
        }
278 36
    }
279
280
    /**
281
     * Indicate ringing to a channel.
282
     *
283
     * @param string $channelId
284
     * @throws NotFoundException
285
     * @throws ConflictException
286
     */
287 View Code Duplication
    public function startRinging($channelId)
0 ignored issues
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...
288
    {
289
        $uri = "/channels/$channelId/ring";
290
        try {
291
            $this->client->getEndpoint()->post($uri, array());
292
        } catch (Pest_NotFound $e) {
293
            throw new NotFoundException($e);
294
        } catch (Pest_Conflict $e) {
295
            throw new ConflictException($e);
296
        }
297
    }
298
299
    /**
300
     * Stop ringing indication on a channel if locally generated.
301
     *
302
     * @param string $channelId
303
     * @throws NotFoundException
304
     * @throws ConflictException
305
     */
306 View Code Duplication
    public function stopRinging($channelId)
0 ignored issues
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...
307
    {
308
        $uri = "/channels/$channelId/ring";
309
        try {
310
            $this->client->getEndpoint()->delete($uri);
311
        } catch (Pest_NotFound $e) {
312
            throw new NotFoundException($e);
313
        } catch (Pest_Conflict $e) {
314
            throw new ConflictException($e);
315
        }
316
    }
317
318
    /**
319
     * Send provided DTMF to a given channel.
320
     *
321
     * @param string $channelId
322
     * @param string $dtmf DTMF To send.
323
     * @param int $before Amount of time to wait before DTMF digits (specified in milliseconds) start.
324
     * @param int $between Amount of time in between DTMF digits (specified in milliseconds).  Default: 100
325
     * @param int $duration Length of each DTMF digit (specified in milliseconds).  Default: 100
326
     * @param int $after Amount of time to wait after DTMF digits (specified in milliseconds) end.
327
     * @throws InvalidParameterException
328
     * @throws NotFoundException
329
     * @throws ConflictException
330
     */
331
    public function sendDtmf($channelId, $dtmf, $before = null, $between = null, $duration = null, $after = null)
332
    {
333
        $uri = "/channels/$channelId/dtmf";
334
        try {
335
            $this->client->getEndpoint()->post($uri, array(
336
                'dtmf' => $dtmf,
337
                'before' => $before,
338
                'between' => $between,
339
                'duration' => $duration,
340
                'after' => $after,
341
            ));
342
        } catch (Pest_BadRequest $e) {
343
            throw new InvalidParameterException($e);
344
        } catch (Pest_NotFound $e) {
345
            throw new NotFoundException($e);
346
        } catch (Pest_Conflict $e) {
347
            throw new ConflictException($e);
348
        }
349
    }
350
351
    /**
352
     * Mute a channel.
353
     *
354
     * @param string $channelId Channel's id
355
     * @param string $direction (default both) Direction in which to mute audio.  Allowed values: both, in, out
356
     * @throws NotFoundException
357
     * @throws ConflictException
358
     */
359
    public function mute($channelId, $direction)
360
    {
361
        $uri = "/channels/$channelId/mute";
362
        try {
363
            $this->client->getEndpoint()->post($uri, array(
364
                'direction' => $direction,
365
            ));
366
        } catch (Pest_NotFound $e) {
367
            throw new NotFoundException($e);
368
        } catch (Pest_Conflict $e) {
369
            throw new ConflictException($e);
370
        }
371
    }
372
373
    /**
374
     * Unmute a channel.
375
     *
376
     * @param string $channelId Channel's id
377
     * @param string $direction (default both) Direction in which to unmute audio
378
     * @throws NotFoundException
379
     * @throws ConflictException
380
     */
381 View Code Duplication
    public function unmute($channelId, $direction)
0 ignored issues
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...
382
    {
383
        $uri = "/channels/$channelId/mute?direction=".$this->client->getEndpoint()->jsonEncode($direction);
384
        try {
385
            $this->client->getEndpoint()->delete($uri);
386
        } catch (Pest_NotFound $e) {
387
            throw new NotFoundException($e);
388
        } catch (Pest_Conflict $e) {
389
            throw new ConflictException($e);
390
        }
391
    }
392
393
    /**
394
     * Hold a channel.
395
     *
396
     * @param string $channelId Channel's id
397
     * @throws NotFoundException
398
     * @throws ConflictException
399
     */
400 View Code Duplication
    public function hold($channelId)
0 ignored issues
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...
401
    {
402
        $uri = "/channels/$channelId/hold";
403
        try {
404
            $this->client->getEndpoint()->post($uri, array());
405
        } catch (Pest_NotFound $e) {
406
            throw new NotFoundException($e);
407
        } catch (Pest_Conflict $e) {
408
            throw new ConflictException($e);
409
        }
410
    }
411
412
    /**
413
     * Remove a channel from hold.
414
     *
415
     * @param string $channelId Channel's id
416
     * @throws NotFoundException
417
     * @throws ConflictException
418
     */
419 View Code Duplication
    public function unhold($channelId)
0 ignored issues
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...
420
    {
421
        $uri = "/channels/$channelId/hold";
422
        try {
423
            $this->client->getEndpoint()->delete($uri);
424
        } catch (Pest_NotFound $e) {
425
            throw new NotFoundException($e);
426
        } catch (Pest_Conflict $e) {
427
            throw new ConflictException($e);
428
        }
429
    }
430
431
    /**
432
     * Play silence to a channel. Using media operations such as /play on a channel playing silence in this manner will suspend silence without resuming automatically.
433
     *
434
     * @param string $channelId Channel's id
435
     * @throws NotFoundException
436
     * @throws ConflictException
437
     */
438 View Code Duplication
    public function startSilence($channelId)
0 ignored issues
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...
439
    {
440
        $uri = "/channels/$channelId/silence";
441
        try {
442
            $this->client->getEndpoint()->post($uri, array());
443
        } catch (Pest_NotFound $e) {
444
            throw new NotFoundException($e);
445
        } catch (Pest_Conflict $e) {
446
            throw new ConflictException($e);
447
        }
448
    }
449
450
    /**
451
     * Stop playing silence to a channel.
452
     *
453
     * @param string $channelId Channel's id
454
     * @throws NotFoundException
455
     * @throws ConflictException
456
     */
457 View Code Duplication
    public function stopSilence($channelId)
0 ignored issues
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...
458
    {
459
        $uri = "/channels/$channelId/silence";
460
        try {
461
            $this->client->getEndpoint()->delete($uri);
462
        } catch (Pest_NotFound $e) {
463
            throw new NotFoundException($e);
464
        } catch (Pest_Conflict $e) {
465
            throw new ConflictException($e);
466
        }
467
    }
468
469
    /**
470
     * Get the value of a channel variable or function.
471
     *
472
     * @param string $channelId
473
     * @param string $variable
474
     * @param null|string $default The value to return if the variable does not exist
475
     * @return string|Variable
476
     * @throws ConflictException
477
     * @throws InvalidParameterException
478
     * @throws NotFoundException
479
     */
480
    public function getVariable($channelId, $variable, $default = null)
481
    {
482
        $uri = "/channels/$channelId/variable";
483
        try {
484
            $response = $this->client->getEndpoint()->get($uri, array(
485
                'variable' => $variable,
486
            ));
487
        } catch (Pest_BadRequest $e) { // Missing variable parameter.
488
            throw new InvalidParameterException($e);
489
        } catch (Pest_NotFound $e) { // Variable not found
490
            if ($default !== null) {
491
                return $default;
492
            }
493
            throw new NotFoundException($e);
494
        } catch (Pest_Conflict $e) { // Channel not in a Stasis application
495
            throw new ConflictException($e);
496
        }
497
498
        return new Variable($response);
499
    }
500
501
    /**
502
     * Set the value of a channel variable or function.
503
     *
504
     * @param string $channelId
505
     * @param string $variable
506
     * @param string $value
507
     * @return Variable
508
     * @throws InvalidParameterException
509
     * @throws NotFoundException
510
     * @throws ConflictException
511
     */
512
    public function setVariable($channelId, $variable, $value)
513
    {
514
        $uri = "/channels/$channelId/variable";
515
        try {
516
            $response = $this->client->getEndpoint()->post($uri, array(
517
                'variable' => $variable,
518
                'value' => $value,
519
            ));
520
        } catch (Pest_BadRequest $e) { // Missing variable parameter.
521
            throw new InvalidParameterException($e);
522
        } catch (Pest_NotFound $e) { // Channel not found
523
            throw new NotFoundException($e);
524
        } catch (Pest_Conflict $e) { // Channel not in a Stasis application
525
            throw new ConflictException($e);
526
        }
527
528
        return new Variable($response);
529
    }
530
531
    /**
532
     * Start snooping. Snoop (spy/whisper) on a specific channel.
533
     *
534
     * @param string $channelId Channel's id
535
     * @param string $spy (default none) Direction of audio to spy on
536
     * @param string $whisper (default none) Direction of audio to whisper into
537
     * @param string $app (required) Application the snooping channel is placed into
538
     * @param string $appArgs The application arguments to pass to the Stasis application
539
     * @param string $snoopId Unique ID to assign to snooping channel
540
     * @return Channel
541
     * @throws InvalidParameterException
542
     * @throws NotFoundException
543
     */
544 View Code Duplication
    public function startSnoop($channelId, $spy, $whisper, $app, $appArgs, $snoopId)
0 ignored issues
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...
545
    {
546
        $uri = "/channels/$channelId/snoop";
547
        try {
548
            $response = $this->client->getEndpoint()->post($uri, array(
549
                'spy' => $spy,
550
                'whisper' => $whisper,
551
                'app' => $app,
552
                'appArgs' => $appArgs,
553
                'snoopId' => $snoopId,
554
            ));
555
        } catch (Pest_BadRequest $e) { // Missing parameters
556
            throw new InvalidParameterException($e);
557
        } catch (Pest_NotFound $e) { // Channel not found
558
            throw new NotFoundException($e);
559
        }
560
561
        return new Channel($this->client, $response);
562
    }
563
564
    /**
565
     * Start snooping. Snoop (spy/whisper) on a specific channel.
566
     *
567
     * @param string $channelId Channel's id
568
     * @param string $spy (default none) Direction of audio to spy on
569
     * @param string $whisper (default none) Direction of audio to whisper into
570
     * @param string $app (required) Application the snooping channel is placed into
571
     * @param string $appArgs The application arguments to pass to the Stasis application
572
     * @param string $snoopId Unique ID to assign to snooping channel
573
     * @return Channel
574
     * @throws InvalidParameterException
575
     * @throws NotFoundException
576
     */
577 View Code Duplication
    public function startSnoopWithId($channelId, $spy, $whisper, $app, $appArgs, $snoopId)
0 ignored issues
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...
578
    {
579
        $uri = "/channels/$channelId/snoop/$snoopId";
580
        try {
581
            $response = $this->client->getEndpoint()->post($uri, array(
582
                'spy' => $spy,
583
                'whisper' => $whisper,
584
                'app' => $app,
585
                'appArgs' => $appArgs,
586
            ));
587
        } catch (Pest_BadRequest $e) { // Missing parameters
588
            throw new InvalidParameterException($e);
589
        } catch (Pest_NotFound $e) { // Channel not found
590
            throw new NotFoundException($e);
591
        }
592
593
        return new Channel($this->client, $response);
594
    }
595
596
    /**
597
     * @return string
598
     */
599 6
    public function getType()
600
    {
601 6
        return 'channels';
602
    }
603
}
604