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

HttpClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 62.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 51
ccs 15
cts 24
cp 0.625
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setAuth() 0 6 1
A getClient() 0 9 2
A setClient() 0 4 1
A get() 0 17 2
1
<?php
2
3
namespace Rundeck;
4
5
class HttpClient
6
{
7
8
    private $client;
9
    private $endpoint;
10
    private $authToken;
11
    private $version;
12
13
    public function setAuth($endpoint, $authToken, $version)
14
    {
15
        $this->endpoint = trim($endpoint, "/");
16
        $this->authToken = $authToken;
17
        $this->version = $version;
18
    }
19
20 15
    public function getClient()
21
    {
22 15
        if (isset($this->client)) {
23 15
            return $this->client;
24
        } else {
25
            $this->client = new \GuzzleHttp\Client();
26
            return $this->client;
27
        }
28
    }
29
30
    /**
31
     * @param mixed $client
32
     */
33 15
    public function setClient($client)
34
    {
35 15
        $this->client = $client;
36 15
    }
37
38 15
    public function get($uri, $alt)
39
    {
40 15
        $options = ['headers'=> ['Accept' => 'application/xml']];
41
42 15
        if ($alt == "json") {
43
            $options = ['headers'=> ['Accept' => 'application/json']];
44
        }
45 15
        $uri = $this->endpoint. "/api/". $this->version .$uri."?authtoken=".$this->authToken;
46
47 15
        $response = $this->getClient()->request('GET', $uri, $options);
48 15
        $xml = simplexml_load_string($response->getBody());
49 15
        $json = json_encode($xml);
50 15
        $data = json_decode($json, true);
51
52
        //echo $response->getBody(); die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53 15
        return $data;
54
    }
55
}
56