Completed
Push — master ( cc864c...f8b489 )
by Akram
02:32
created

Execution::__construct()   A

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 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Rundeck\Resources;
4
5
use Rundeck\HttpClient;
6
7
/**
8
 * Class Execution /api/V/execution/
9
 * @package Rundeck\Resources
10
 */
11
class Execution
12
{
13
    /**
14
     * @var null|string
15
     */
16
    private $name;
17
18
    /**
19
     * @var HttpClient
20
     */
21
    private $client;
22
23
    private $actions = [
24
        "abort" => ["xml"], // /api/V/execution/[ID]/abort
25
        "output" => ["xml"], // /api/V/execution/[ID]/output
26
        "output/state" => ["xml"], // /api/V/execution/[ID]/output/state
27
        "state" => ["xml"], // /api/V/execution/[ID]/state
28
        "input/files" => ["xml"], // /api/V/execution/[ID]/input/files
29
    ];
30
31
    /**
32
     * @param HttpClient $client
33
     * @param string $name : Execution ID
34
     */
35 15
    public function __construct(HttpClient $client, $name = null)
36
    {
37 15
        $this->name = $name;
38 15
        $this->client = $client;
39 15
    }
40
41
    /**
42
     * Find execution info by ID
43
     * @param string $alt
44
     * @return mixed
45
     */
46 3
    public function find($alt = "xml")
47
    {
48 3
        $response = $this->client->get('/execution/'.$this->name, $alt);
49 3
        return $response;
50
    }
51
52
    /**
53
     * Get Execution action
54
     * @param $action
55
     * @param string $alt xml|json
56
     * @return array
57
     * @throws \Exception
58
     */
59 12 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...
60
    {
61 12
        if (array_key_exists($action, $this->actions)) {
62 12
            if (!in_array($alt, $this->actions[$action])) {
63
                throw new \Exception("Invalid Format: ". $alt);
64
            }
65 12
            $response = $this->client->get('/execution/'.$this->name. '/' .$action, $alt);
66 12
            return $response;
67
        } else {
68
            throw new \Exception("Action invalid.");
69
        }
70
    }
71
}
72