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

Resource::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
crap 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