Completed
Push — master ( a3a7cd...21af45 )
by Brian
21s
created

Sounds   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 55.88 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 19
loc 34
ccs 6
cts 12
cp 0.5
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSounds() 12 12 2
A getSound() 7 7 1

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 phparia\Client\AriClientAware;
22
use phparia\Resources\Sound;
23
24
/**
25
 * Sounds API
26
 *
27
 * @author Brian Smith <[email protected]>
28
 */
29
class Sounds extends AriClientAware
30
{
31
    /**
32
     * List all sounds.
33
     *
34
     * @return Sound[]
35
     */
36 1 View Code Duplication
    public function getSounds()
37
    {
38 1
        $uri = 'sounds';
39 1
        $response = $this->client->getEndpoint()->get($uri);
40
41
        $sounds = [];
42
        foreach (\GuzzleHttp\json_decode($response->getBody()) as $sound) {
43
            $sounds[] = new Sound($sound);
44
        }
45
46
        return $sounds;
47
    }
48
49
    /**
50
     * Get a sound's details.
51
     *
52
     * @param string $soundId Sound's id
53
     * @return Sound
54
     */
55 1 View Code Duplication
    public function getSound($soundId)
56
    {
57 1
        $uri = "sounds/$soundId";
58 1
        $response = $this->client->getEndpoint()->get($uri);
59
60
        return new Sound(\GuzzleHttp\json_decode($response->getBody()));
61
    }
62
}
63