Completed
Push — master ( 1777e6...510d36 )
by Mikhail
01:24
created

Api   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 33.87 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 21
loc 62
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 7 7 1
A post() 7 7 1
A delete() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace R3bers\BittrexApi\Api;
6
7
use Exception;
8
use GuzzleHttp\Client;
9
use R3bers\BittrexApi\Message\ResponseTransformer;
10
11
/**
12
 * Class Api
13
 * @package R3bers\BittrexApi\Api
14
 */
15
class Api
16
{
17
    /** @var Client */
18
    protected $client;
19
    /** @var ResponseTransformer */
20
    protected $transformer;
21
    /** @var string */
22
    private $version = 'v3';
23
    private $endpoint = '/api/';
24
25
    /**
26
     * Api constructor.
27
     * @param Client $client
28
     */
29 23
    public function __construct(Client $client)
30
    {
31 23
        $this->client = $client;
32 23
        $this->transformer = new ResponseTransformer();
33 23
    }
34
35
    /**
36
     * @param string $uri
37
     * @param array $query
38
     * @return array
39
     * @throws Exception
40
     */
41 17 View Code Duplication
    public function get(string $uri, array $query = []): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43 17
        $response = $this->client->request('GET', $this->endpoint . $this->version
44 17
            . $uri, ['query' => $query]);
45
46 17
        return $this->transformer->transform($response);
47
    }
48
49
    /**
50
     * @param string $uri
51
     * @param array $query
52
     * @return array
53
     * @throws Exception
54
     */
55 2 View Code Duplication
    public function post(string $uri, array $query = []): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57 2
        $response = $this->client->request('POST', $this->endpoint . $this->version
58 2
            . $uri, ['query' => $query]);
59
60 2
        return $this->transformer->transform($response);
61
    }
62
63
    /**
64
     * @param string $uri
65
     * @param array $query
66
     * @return array
67
     * @throws Exception
68
     */
69 1 View Code Duplication
    public function delete(string $uri, array $query = []): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71 1
        $response = $this->client->request('DELETE', $this->endpoint . $this->version
72 1
            . $uri, ['query' => $query]);
73
74 1
        return $this->transformer->transform($response);
75
    }
76
}
77