Completed
Push — master ( a72aaa...aa1c76 )
by Brian
03:39
created

Channels   C

Complexity

Total Complexity 63

Size/Duplication

Total Lines 554
Duplicated Lines 24.19 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 15.84%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 63
c 5
b 0
f 1
lcom 1
cbo 9
dl 134
loc 554
ccs 35
cts 221
cp 0.1584
rs 5.8893

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getChannels() 0 12 2
B createChannel() 0 38 3
A getChannel() 0 11 2
B createChannelWithId() 0 35 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
A hangup() 0 8 2
A deleteChannel() 9 9 2

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