Completed
Push — master ( a7cfbd...fecc98 )
by Akram
02:05
created

System::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
cc 2
eloc 6
nc 2
nop 2
crap 2.032
1
<?php
2
3
namespace Rundeck\Resources;
4
5
use Rundeck\HttpClient;
6
7
/**
8
 * Class System /api/V/system/
9
 * @package Rundeck\Resources
10
 */
11
class System
12
{
13
    /**
14
     * @var null
15
     */
16
    private $name;
17
18
    /**
19
     * @var HttpClient
20
     */
21
    private $client;
22
23
    /**
24
     * @var array
25
     */
26
    private $actions = [
27
        "info", // /api/V/system/info
28
        "logstorage", // /api/V/system/logstorage
29
        "logstorage/incomplete" // /api/V/system/logstorage/incomplete
30
    ];
31
32
    /**
33
     * @param HttpClient $client
34
     * @param null $name
35
     */
36 9
    public function __construct(HttpClient $client, $name = null)
37
    {
38 9
        $this->name = $name;
39 9
        $this->client = $client;
40 9
    }
41
42
    /**
43
     * Get System action
44
     * @param $action
45
     * @param string $alt xml|json
46
     * @return array
47
     * @throws \Exception
48
     */
49 9
    public function get($action, $alt = "xml")
50
    {
51 9
        if (in_array($action, $this->actions)) {
52 9
            $response = $this->client->get('/system/'. $action, $alt);
53 9
            return $response;
54
        } else {
55
            throw new \Exception("Action invalid.");
56
        }
57
    }
58
}
59