ResponseHandlerBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 16 3
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Core\Builders;
4
5
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface;
7
use Carpenstar\ByBitAPI\Core\Interfaces\ISuccessCurlResponseDtoInterface;
8
use Carpenstar\ByBitAPI\Core\Interfaces\IFabricInterface;
9
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseDataInterface;
10
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseHandlerInterface;
11
12
class ResponseHandlerBuilder implements IFabricInterface
13
{
14
    /**
15
     * @param string $data
16
     * @param string|null $curlResponse
17
     * @param string|null $dto
18
     * @param int $resultMode
19
     * @return IResponseInterface
20
     * @throws \Exception
21
     */
22
    public static function make(string $data, string $curlResponse = null, string $dto = null): IResponseInterface
23
    {
24
        if (!in_array(IResponseHandlerInterface::class, class_implements($curlResponse))) {
25
            throw new \Exception("{$dto} must be implements the interface " . IResponseHandlerInterface::class . "!");
26
        }
27
28
        if (!in_array(IResponseDataInterface::class, class_implements($dto))) {
29
            throw new \Exception("{$dto} must be implements the interface " . IResponseDataInterface::class . "!");
30
        }
31
32
        /**
33
         * @var IResponseHandlerInterface $curlResponse
34
         */
35
        $curlResponse = new $curlResponse();
36
37
        return $curlResponse->build($data, $dto);
0 ignored issues
show
Bug introduced by
$data of type string is incompatible with the type array expected by parameter $apiData of Carpenstar\ByBitAPI\Core...ndlerInterface::build(). ( Ignorable by Annotation )

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

37
        return $curlResponse->build(/** @scrutinizer ignore-type */ $data, $dto);
Loading history...
Bug introduced by
It seems like $dto can also be of type null; however, parameter $dto of Carpenstar\ByBitAPI\Core...ndlerInterface::build() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

37
        return $curlResponse->build($data, /** @scrutinizer ignore-type */ $dto);
Loading history...
38
    }
39
}
40