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

ResponseDtoBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 4
c 0
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 7 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
}