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

HttpClient::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.024

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
ccs 9
cts 11
cp 0.8182
rs 9.4285
cc 2
eloc 10
nc 2
nop 2
crap 2.024
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