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

ResponseDtoBuilder::make()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
1
<?php
2
namespace Carpenstar\ByBitAPI\Core\Builders;
3
4
use Carpenstar\ByBitAPI\Core\Interfaces\IFabricInterface;
5
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseDataInterface;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseHandlerInterface;
7
8
class ResponseDtoBuilder implements IFabricInterface
9
{
10
    /**
11
     * @param string $className
12
     * @param array|null $data
13
     * @return IResponseDataInterface
14
     * @throws \Exception
15
     */
16
    public static function make(string $className, ?array $data = null): IResponseDataInterface
17
    {
18
        if (!in_array(IResponseDataInterface::class, class_implements($className))) {
19
            throw new \Exception("That DTO {$className} must be implements the interface " . IResponseHandlerInterface::class . "!");
20
        }
21
22
        return new $className($data);
23
    }
24
}