Rundeck::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Rundeck;
4
5
class Rundeck
6
{
7
    /**
8
     * @var HttpClient
9
     */
10
    private $client;
11
12
    /**
13
     * Create a new Rundeck Instance
14
     */
15 3
    public function __construct($endpoint, $authToken, $version)
16
    {
17 3
        $this->client = new HttpClient();
18 3
        $this->client->setAuth($endpoint, $authToken, $version);
19 3
    }
20
21
    /**
22
     * @param HttpClient $client
23
     */
24 3
    public function setClient($client)
25
    {
26 3
        $this->client = $client;
27 3
    }
28
29
    /**
30
     * @param $name
31
     * @param $arguments
32
     * @return object
33
     * @throws \Exception
34
     */
35 3
    public function __call($name, $arguments)
36
    {
37 3
        $className = "\\Rundeck\\Resources\\".ucfirst($name);
38 3
        if (class_exists($className)) {
39 3
            array_unshift($arguments, $this->client);
40 3
            $resource = new \ReflectionClass($className);
41 3
            return $resource->newInstanceArgs($arguments);
42
        } else {
43
            throw new \Exception("This resource doesn't exist.");
44
        }
45
    }
46
}
47