Completed
Push — master ( 281270...5bd029 )
by Fabian
01:52
created

PostRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 9.52 %

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
dl 6
loc 63
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNonce() 6 6 1
A __construct() 0 5 1
A execute() 0 15 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
 * @author  Fabian Hanisch
4
 * @since   16.07.2017 02:40
5
 * @version 1.0
6
 */
7
8
namespace HanischIt\KrakenApi\Service\RequestService;
9
10
use HanischIt\KrakenApi\Enum\RequestMethodEnum;
11
use HanischIt\KrakenApi\External\HttpClient;
12
use HanischIt\KrakenApi\Model\Header;
13
use HanischIt\KrakenApi\Model\RequestInterface;
14
use HanischIt\KrakenApi\Model\RequestOptions;
15
16
/**
17
 * Class PostRequest
18
 *
19
 * @package HanischIt\KrakenApi\Service\RequestService
20
 */
21
class PostRequest
22
{
23
    /**
24
     * @var HttpClient
25
     */
26
    private $client;
27
    /**
28
     * @var RequestHeader
29
     */
30
    private $requestHeader;
31
    /**
32
     * @var Nonce
33
     */
34
    private $nonce;
35
36
    /**
37
     * Request constructor.
38
     *
39
     * @param HttpClient    $client
40
     * @param RequestHeader $requestHeader
41
     * @param Nonce         $nonce
42
     */
43 1
    public function __construct(HttpClient $client, RequestHeader $requestHeader, Nonce $nonce)
44
    {
45 1
        $this->client = $client;
46 1
        $this->requestHeader = $requestHeader;
47 1
        $this->nonce = $nonce;
48 1
    }
49
50
    /**
51
     * @param RequestInterface $request
52
     * @param RequestOptions   $requestOptions
53
     * @param Header           $header
54
     *
55
     * @return \Psr\Http\Message\ResponseInterface
56
     */
57 1
    public function execute(RequestInterface $request, RequestOptions $requestOptions, Header $header)
58
    {
59 1
        $nonce = $this->nonce->generate();
60 1
        $requestData = $request->getRequestData();
61 1
        $requestData["nonce"] = $nonce;
62 1
        $path = $requestOptions->getEndpoint() . $requestOptions->getVersion() . "/private/" . $request->getMethod();
63
64 1
        return $this->client->request(RequestMethodEnum::REQUEST_METHOD_POST, $path, [
65 1
            'headers' => $this->requestHeader->asArray(
66 1
                $header,
67 1
                $requestData,
68 1
                "/" . $requestOptions->getVersion() . "/private/" . $request->getMethod(),
69
                $nonce
70 1
            ),
71
            'form_params' => $requestData
72 1
        ]);
73
    }
74
75
    /**
76
     * @return string
77
     */
78 View Code Duplication
    private function getNonce()
0 ignored issues
show
Unused Code introduced by
The method getNonce() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
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...
79
    {
80
        $nonce = explode(' ', microtime());
81
        $nonce = $nonce[1] . str_pad(substr($nonce[0], 2, 6), 6, '0');
82
83
        return $nonce;
84
    }
85
}
86