CurlResponseHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 2
b 0
f 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 6 2
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Core\Response;
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']);
0 ignored issues
show
Unused Code introduced by
The call to Carpenstar\ByBitAPI\Core...Response::__construct() has too many arguments starting with $apiData['retMsg']. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
            return /** @scrutinizer ignore-call */ new ExceptionResponse($apiData['retCode'], $apiData['retMsg'], $apiData['retExtInfo'], $apiData['time']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug Best Practice introduced by
The expression return new Carpenstar\By...fo'], $apiData['time']) returns the type Carpenstar\ByBitAPI\Core\Objects\ExceptionResponse which is incompatible with the type-hinted return Carpenstar\ByBitAPI\Core...aces\IResponseInterface.
Loading history...
23
        }
24
    }
25
}
26