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

Client   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 38
ccs 7
cts 14
cp 0.5
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B getResponse() 0 18 6
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
}