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

ContainerApiFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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