Completed
Pull Request — master (#14)
by Pavel
05:32 queued 02:29
created

ApiFactory/ApiFactoryRegistryFactory.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Bankiru\Api\Doctrine\ApiFactory;
4
5
use Bankiru\Api\Doctrine\ApiFactoryInterface;
6
use Bankiru\Api\Doctrine\ApiFactoryRegistryInterface;
7
use Bankiru\Api\Doctrine\Exception\ApiFactoryRegistryException;
8
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
9
use ScayTrase\Api\Rpc\RpcClientInterface;
10
11
final class ApiFactoryRegistryFactory implements ApiFactoryRegistryInterface
12
{
13
    /** @var  ApiFactoryInterface[] */
14
    private $factories = [];
15
16
    /** {@inheritdoc} */
17 View Code Duplication
    public function create($alias, RpcClientInterface $client, ApiMetadata $metadata)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        if (!$this->has($alias)) {
20
            throw ApiFactoryRegistryException::unknown($alias);
21
        }
22
23
        return $this->factories[$alias]->createApi($client, $metadata);
24
    }
25
26
    /** {@inheritdoc} */
27 17
    public function has($alias)
28
    {
29 17
        return array_key_exists($alias, $this->factories);
30
    }
31
32
    /** {@inheritdoc} */
33
    public function set($alias, ApiFactoryInterface $factory)
34
    {
35
        $this->factories[$alias] = $factory;
36
    }
37
}
38