Completed
Push — master ( fecc98...3c243b )
by Akram
02:27
created

Project::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Rundeck\Resources;
4
5
use Rundeck\HttpClient;
6
7
/**
8
 * Class Project /api/V/project/
9
 * @package Rundeck\Resources
10
 */
11
class Project
12
{
13
14
    /**
15
     * @var null|string
16
     */
17
    private $name;
18
19
    /**
20
     * @var HttpClient
21
     */
22
    private $client;
23
24
    /**
25
     * @var array
26
     */
27
    private $actions = [
28
        "jobs" => ["xml"],
29
        "jobs/export" => ["xml"],
30
        "resources" => ["xml"],
31
        "executions" => ["xml"],
32
        "executions/running" => ["xml"],
33
        "export" => ["xml"],
34
        "history" => ["xml"],
35
    ];
36
37
    /**
38
     * @param HttpClient $client
39
     * @param string $name : Execution ID
40
     */
41 12
    public function __construct(HttpClient $client, $name = null)
42
    {
43 12
        $this->name = $name;
44 12
        $this->client = $client;
45 12
    }
46
47
    /**
48
     * Get project info
49
     * @param string $alt xml|json
50
     * @return array
51
     */
52 3
    public function find($alt = "xml")
53
    {
54 3
        $response = $this->client->get('/project/'.$this->name, $alt);
55 3
        return $response;
56
    }
57
58
    /**
59
     * Find all projects
60
     * @param string $alt
61
     * @return array
62
     */
63 3
    public function findAll($alt = "xml")
64
    {
65 3
        $response = $this->client->get('/projects', $alt);
66 3
        return $response;
67
    }
68
69
    /**
70
     * Get Project action
71
     * @param $action
72
     * @param string $alt xml|json
73
     * @return array
74
     * @throws \Exception
75
     */
76 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...
77
    {
78 3
        if (array_key_exists($action, $this->actions)) {
79 3
            if (!in_array($alt, $this->actions[$action])) {
80
                throw new \Exception("Invalid Format: ". $alt);
81
            }
82 3
            $response = $this->client->get('/project/'.$this->name. '/' .$action, $alt);
83 3
            return $response;
84
        } else {
85
            throw new \Exception("Action invalid.");
86
        }
87
    }
88
89
    /**
90
     * Get project resource
91
     * @param $name
92
     * @param string $alt xml|json
93
     * @return array
94
     */
95 3
    public function resource($name, $alt = "xml")
96
    {
97 3
        $response = $this->client->get('/project/'.$this->name. '/resource/' .$name, $alt);
98 3
        return $response;
99
    }
100
}
101