Resource   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 54
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A setParams() 0 4 1
A getParams() 0 4 1
A getPath() 0 4 1
A getVerb() 0 4 1
A isValidVerb() 0 6 2
A isValidPath() 0 4 2
1
<?php
2
3
namespace Njasm\Soundcloud\Resource;
4
5
/**
6
 * SoundCloud API wrapper in PHP
7
 *
8
 * @author      Nelson J Morais <[email protected]>
9
 * @copyright   2014 Nelson J Morais <[email protected]>
10
 * @license     http://www.opensource.org/licenses/mit-license.php MIT
11
 * @link        http://github.com/njasm/soundcloud
12
 * @package     Njasm\Soundcloud
13
 */
14
15
class Resource implements ResourceInterface
16
{
17
    private $path;
18
    private $params = array();
19
    private $verb;
20
    private $availableVerbs = array('get', 'post', 'put', 'delete', 'patch', 'options');
21
    
22 27
    public function __construct($verb = null, $path = null, array $params = array())
23
    {
24 27
        $this->isValidVerb($verb);
25 26
        $this->verb = $verb;
26 26
        $this->params = $params;
27
        
28 26
        if ($this->isValidPath($path) === false) {
29 1
            throw new \RuntimeException(
30 1
                "Path cannot be other then a string type and should start with a '/' (Slash)."
31
            );
32
        }
33
        
34 25
        $this->path = $path;
35 25
    }
36
    
37 6
    public function setParams(array $params = array())
38
    {
39 6
        $this->params = array_merge($this->params, $params);
40 6
    }
41
    
42 14
    public function getParams()
43
    {
44 14
        return $this->params;
45
    }
46
    
47 13
    public function getPath()
48
    {
49 13
        return $this->path;
50
    }
51
    
52 17
    public function getVerb()
53
    {
54 17
        return $this->verb;
55
    }
56
    
57 27
    private function isValidVerb($verb)
58
    {
59 27
        if (in_array(strtolower($verb), $this->availableVerbs) === false) {
60 1
            throw new \OutOfBoundsException("Resource of type: $verb, not available!");
61
        }
62 26
    }
63
    
64 26
    private function isValidPath($path)
65
    {
66 26
        return is_string($path) === true && substr($path, 0, 1) === "/";
67
    }
68
}
69