Completed
Push — master ( 65a985...a63df8 )
by Akram
02:31
created

Job::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 12
loc 12
ccs 5
cts 7
cp 0.7143
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
crap 3.2098
1
<?php
2
3
namespace Rundeck\Resources;
4
5
use Rundeck\HttpClient;
6
7
/**
8
 * Class Job
9
 * @package Rundeck\Resources
10
 */
11
class Job
12
{
13
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
19
    /**
20
     * @var HttpClient
21
     */
22
    private $client;
23
24
    /**
25
     * @var array
26
     */
27
    private $actions = [
28
        "executions" => ["xml"],
29
        "input/files" => ["xml"],
30
        "info" => ["xml"],
31
    ];
32
33
    /**
34
     * @param HttpClient $client
35
     * @param string $name
36
     */
37 6
    public function __construct(HttpClient $client, $name = null)
38
    {
39 6
        $this->name = $name;
40 6
        $this->client = $client;
41 6
    }
42
43
    /**
44
     * @param string $alt
45
     * @return mixed
46
     */
47 3
    public function find($alt = "xml")
48
    {
49 3
        $response = $this->client->get('/job/'.$this->name, $alt);
50 3
        return $response;
51
    }
52
53
    /**
54
     * Get Job action
55
     * @param $action
56
     * @param string $alt xml|json
57
     * @return array
58
     * @throws \Exception
59
     */
60 3 View Code Duplication
    public function get($action, $alt = "xml")
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62 3
        if (array_key_exists($action, $this->actions)) {
63 3
            if (!in_array($alt, $this->actions[$action])) {
64
                throw new \Exception("Invalid Format: ". $alt);
65
            }
66 3
            $response = $this->client->get('/job/'.$this->name. '/' .$action, $alt);
67 3
            return $response;
68
        } else {
69
            throw new \Exception("Action invalid.");
70
        }
71
    }
72
}
73