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

Execution   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 19.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 1
dl 12
loc 61
ccs 12
cts 14
cp 0.8571
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A find() 0 5 1
A get() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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