Request::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
crap 1
1
<?php
2
3
namespace JulianoBailao\DomusApi\Core;
4
5
use GuzzleHttp\Client;
6
7
class Request
8
{
9
    /**
10
     * The client ai handle.
11
     *
12
     * @var mixed
13
     */
14
    protected $handler;
15
16
    /**
17
     * Create new Request instance.
18
     *
19
     * @param mixed $handler
20
     */
21 132
    public function __construct($handler)
22
    {
23 132
        $this->handler = $handler;
24 132
    }
25
26
    /**
27
     * Run the request.
28
     *
29
     * @param string $method
30
     * @param string $url
31
     * @param array  $data
32
     *
33
     * @return string
34
     */
35 132
    public function run($method, $url, array $data = [])
36
    {
37 132
        $client = new Client(['handler' => $this->handler]);
38
39 132
        return json_decode($client->request($method, $url, array_merge($data, [
40 132
            'Accept'       => 'application/json',
41 132
            'Content-Type' => 'application/json',
42 132
            'uSER-aGENT'   => 'JulianoBailao/DomusApi',
43 132
            'debug'        => true,
44 132
        ]))->getBody());
45
    }
46
}
47