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

Project   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 1
dl 12
loc 90
ccs 18
cts 20
cp 0.9
rs 10

5 Methods

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

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