Completed
Push — master ( 25710f...56c545 )
by Akram
02:12
created

Resource   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
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
abstract class Resource
6
{
7
8
    /**
9
     * @var string
10
     */
11
    protected $name;
12
13
    /**
14
     * @var HttpClient
15
     */
16
    protected $client;
17
18
    /**
19
     * @var array
20
     */
21
    protected $actions;
22
23
    /**
24
     * Get resource action
25
     * @param $action
26
     * @param string $alt xml|json
27
     * @return array
28
     * @throws \Exception
29
     */
30 33
    public function get($action, $alt = "xml")
31
    {
32 33
        if (array_key_exists($action, $this->actions)) {
33 30
            if (!in_array($alt, $this->actions[$action])) {
34 3
                throw new \Exception("Invalid Format: ". $alt);
35
            }
36 27
            $response = $this->client->get('/'. strtolower(get_class($this)) .'/'.$this->name. '/' .$action, $alt);
37 27
            return $response;
38
        } else {
39 3
            throw new \Exception("Invalid Action: ". $action);
40
        }
41
    }
42
}
43