Completed
Pull Request — master (#4)
by Pavel
10:02
created

ContainerApiFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 30
ccs 3
cts 8
cp 0.375
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 7 1
A has() 0 4 2
1
<?php
2
3
namespace Bankiru\Api;
4
5
use Bankiru\Api\Doctrine\ApiFactoryInterface;
6
use Bankiru\Api\Doctrine\ApiFactoryRegistryInterface;
7
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
8
use ScayTrase\Api\Rpc\RpcClientInterface;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
11
final class ContainerApiFactory implements ApiFactoryRegistryInterface
12
{
13
    /** @var  ContainerInterface */
14
    private $container;
15
16
    /**
17
     * ContainerApiFactory constructor.
18
     *
19
     * @param ContainerInterface $container
20
     */
21 4
    public function __construct(ContainerInterface $container)
22
    {
23 4
        $this->container = $container;
24 4
    }
25
26
    /** {@inheritdoc} */
27
    public function create($alias, RpcClientInterface $client, ApiMetadata $metadata)
28
    {
29
        /** @var ApiFactoryInterface $factory */
30
        $factory = $this->container->get($alias);
31
32
        return $factory->createApi($client, $metadata);
33
    }
34
35
    /** {@inheritdoc} */
36
    public function has($alias)
37
    {
38
        return $this->container->has($alias) && $this->container->get($alias) instanceof ApiFactoryInterface;
39
    }
40
}
41