Completed
Push — master ( db0246...91f80b )
by Denis
02:07
created

Client::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.032
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dp
5
 * Date: 25.07.17
6
 * Time: 17:18
7
 */
8
9
namespace Lan\Ebs\Sdk;
10
11
use Exception;
12
use Lan\Ebs\Sdk\Helper\Curl;
13
use Lan\Ebs\Sdk\Helper\Debuger;
14
15
final class Client
16
{
17
    private $token = '';
18
19
    /**
20
     * Ebs constructor.
21
     *
22
     * @param  $token
23
     * @throws Exception
24
     */
25 26
    public function __construct($token)
26
    {
27 26
        if (empty($token)) {
28
            throw new Exception('Token is empty');
29
        }
30
31 26
        $this->token = $token;
32 26
    }
33
34 16
    public function getResponse(array $request, array $params = [])
35
    {
36 16
        if (empty($request['url']) || empty($request['method']) || empty($request['code'])) {
37
            throw new Exception('Request url, method or success_code is missing');
38
        }
39
40 16
        $response = Curl::getResponse($this->host, $request['url'], $request['method'], $this->token, $params);
0 ignored issues
show
Bug introduced by
The property host does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
42
        if (isset($response['debug'])) {
43
            Debuger::dump(['host' => $this->host, 'request' => $request, 'params' => $params, 'response' => $response]);
44
        }
45
46
        if ($response['status'] != $request['code']) {
47
            throw new Exception($response['message'], $response['status']);
48
        }
49
50
        return $response;
51
    }
52
}