Passed
Push — master ( 54c1b4...a67e0e )
by Vladislav
11:20 queued 09:15
created

CurlResponseHandler::handle()   B

Complexity

Conditions 11
Paths 34

Size

Total Lines 63
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 45
c 1
b 0
f 0
dl 0
loc 63
rs 7.3166
cc 11
nc 34
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Carpenstar\ByBitAPI\Core\Response;
3
4
5
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseHandlerInterface;
7
use Carpenstar\ByBitAPI\Core\Objects\ExceptionResponse;
8
use Carpenstar\ByBitAPI\Core\Objects\SuccessResponse;
9
10
class CurlResponseHandler implements IResponseHandlerInterface
11
{
12
    /**
13
     * @param array $apiData
14
     * @param string $dto
15
     * @return IResponseInterface
16
     */
17
    public function build(array $apiData, string $dto): IResponseInterface
18
    {
19
        if ($apiData['retCode'] == 0) {
20
            return new SuccessResponse($dto, $apiData['retCode'], $apiData['retMsg'], $apiData['retExtInfo'], $apiData['result'], $apiData['nextPageCursor'] ?? '');
21
        } else {
22
            return new ExceptionResponse($apiData['retCode'], $apiData['retMsg'], $apiData['retExtInfo'], $apiData['time']);
23
        }
24
    }
25
}
26