Resource   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 12 3
1
<?php
2
3
namespace Rundeck\Resources;
4
5
use Rundeck\HttpClient;
6
7
abstract class Resource
8
{
9
10
    /**
11
     * @var string
12
     */
13
    protected $name;
14
15
    /**
16
     * @var HttpClient
17
     */
18
    protected $client;
19
20
    /**
21
     * @var array
22
     */
23
    protected $actions;
24
25
    /**
26
     * Get resource action
27
     * @param $action
28
     * @param string $alt xml|json
29
     * @return array
30
     * @throws \Exception
31
     */
32 33
    public function get($action, $alt = "xml")
33
    {
34 33
        if (array_key_exists($action, $this->actions)) {
35 30
            if (!in_array($alt, $this->actions[$action])) {
36 3
                throw new \Exception("Invalid Format: ". $alt);
37
            }
38 27
            $response = $this->client->get('/'. strtolower(get_class($this)) .'/'.$this->name. '/' .$action, $alt);
39 27
            return $response;
40
        } else {
41 3
            throw new \Exception("Invalid Action: ". $action);
42
        }
43
    }
44
}
45