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

Project::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Rundeck\Resources;
4
5
use Rundeck\HttpClient;
6
7
class Project
8
{
9
10
    private $name;
11
    private $client;
12
13
    private $actions = [
14
        "jobs" => ["xml"],
15
        "jobs/export" => ["xml"],
16
        "resources" => ["xml"],
17
        "executions" => ["xml"],
18
        "executions/running" => ["xml"],
19
        "export" => ["xml"],
20
        "history" => ["xml"],
21
    ];
22
23
    public function __construct(HttpClient $client, $name = null)
24
    {
25
        $this->name = $name;
26
        $this->client = $client;
27
    }
28
29
    public function find($alt = "xml")
30
    {
31
        $response = $this->client->get('/project/'.$this->name, $alt);
32
        return $response;
33
    }
34
35
    public function findAll($alt = "xml")
36
    {
37
        $response = $this->client->get('/projects', $alt);
38
        return $response;
39
    }
40
41 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...
42
    {
43
        if (array_key_exists($action, $this->actions)) {
44
            if (!in_array($alt, $this->actions[$action])) {
45
                throw new \Exception("Invalid Format: ". $alt);
46
            }
47
            $response = $this->client->get('/project/'.$this->name. '/' .$action, $alt);
48
            return $response;
49
        } else {
50
            throw new \Exception("Action invalid.");
51
        }
52
    }
53
54
    public function resource($name, $alt = "xml")
55
    {
56
        $response = $this->client->get('/project/'.$this->name. '/resource/' .$name, $alt);
57
        return $response;
58
    }
59
}
60