Passed
Push — master ( bdfaa2...ebdd6d )
by Vladislav
51s queued 13s
created

ResponseHandlerBuilder   A

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
namespace Carpenstar\ByBitAPI\Core\Builders;
3
4
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode;
5
use Carpenstar\ByBitAPI\Core\Interfaces\ICurlResponseDtoInterface;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IFabricInterface;
7
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseDataInterface;
8
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseHandlerInterface;
9
10
class ResponseHandlerBuilder implements IFabricInterface
11
{
12
    /**
13
     * @param string $data
14
     * @param string|null $curlResponse
15
     * @param string|null $dto
16
     * @param int $resultMode
17
     * @return ICurlResponseDtoInterface
18
     * @throws \Exception
19
     */
20
    public static function make(string $data, string $curlResponse = null, string $dto = null, int $mode = EnumOutputMode::DEFAULT_MODE): ICurlResponseDtoInterface
21
    {
22
        if (!in_array(IResponseHandlerInterface::class, class_implements($curlResponse))) {
23
            throw new \Exception("{$dto} must be implements the interface " . IResponseHandlerInterface::class . "!");
24
        }
25
26
        if (!in_array(IResponseDataInterface::class, class_implements($dto))) {
27
            throw new \Exception("{$dto} must be implements the interface " . IResponseDataInterface::class . "!");
28
        }
29
30
        /**
31
         * @var IResponseHandlerInterface $curlResponse
32
         */
33
        $curlResponse = new $curlResponse();
34
35
        return $curlResponse->bindEntity($dto)->handle($data, $mode);
0 ignored issues
show
Bug introduced by
It seems like $dto can also be of type null; however, parameter $className of Carpenstar\ByBitAPI\Core...Interface::bindEntity() 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

35
        return $curlResponse->bindEntity(/** @scrutinizer ignore-type */ $dto)->handle($data, $mode);
Loading history...
36
    }
37
}