Completed
Push — master ( af2981...31ae42 )
by Brian
05:42
created

Playbacks   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 34.78 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 7
dl 24
loc 69
ccs 0
cts 24
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlayback() 0 11 2
A stopPlayback() 9 9 2
A controlPlayback() 15 15 4

How to fix   Duplicated Code   

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:

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
    public function getPlayback($playbackId)
51
    {
52
        $uri = "/playbacks/$playbackId";
53
        try {
54
            $response = $this->client->getEndpoint()->get($uri);
55
        } catch (Pest_NotFound $e) { // Playback not found
56
            throw new NotFoundException($e);
57
        }
58
59
        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 View Code Duplication
    public function stopPlayback($playbackId)
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...
69
    {
70
        $uri = "/playbacks/$playbackId";
71
        try {
72
            $this->client->getEndpoint()->delete($uri);
73
        } catch (Pest_NotFound $e) { // Playback not found
74
            throw new NotFoundException($e);
75
        }
76
    }
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 View Code Duplication
    public function controlPlayback($playbackId, $operation)
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...
88
    {
89
        $uri = "/playbacks/$playbackId/control";
90
        try {
91
            $this->client->getEndpoint()->post($uri, array(
92
                'operation' => $operation,
93
            ));
94
        } 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
    }
102
103
}
104