Completed
Pull Request — master (#14)
by Pavel
03:32
created

StaticApiFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1
ccs 8
cts 10
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A createApi() 0 7 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine\ApiFactory;
4
5
use Bankiru\Api\Doctrine\ApiFactoryInterface;
6
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
7
use ScayTrase\Api\Rpc\RpcClientInterface;
8
9
final class StaticApiFactory implements ApiFactoryInterface
10
{
11
    /** @var string */
12
    private $name;
13
14
    /**
15
     * StaticApiFactory constructor.
16
     *
17
     * @param string $name
18
     *
19
     * @throws \LogicException
20
     */
21 17
    public function __construct($name)
22
    {
23 17
        $this->name = (string)$name;
24 17
        if (!class_exists($this->name)) {
25
            throw new \LogicException(sprintf('Class %s does not exist', $name));
26
        }
27 17
        if (!in_array(StaticApiFactoryInterface::class, class_implements($name), true)) {
28
            throw new \LogicException(sprintf('Class %s is not a static factory', $name));
29
        }
30 17
    }
31
32 17
    public function createApi(RpcClientInterface $client, ApiMetadata $metadata)
33
    {
34
        /** @var StaticApiFactoryInterface $class */
35 17
        $class = $this->name;
36
37 17
        return $class::createApi($client, $metadata);
38
    }
39
}
40