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

Job   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 19.35 %

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 62
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 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