Completed
Pull Request — master (#14)
by Pavel
04:11
created

ApiFactoryRegistryFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 29.63 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 8
loc 27
ccs 2
cts 9
cp 0.2222
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 8 8 2
A has() 0 4 1
A set() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\MappingException;
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
Duplication introduced by
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 MappingException::unknownApiFactory($alias);
21
        }
22
23
        return $this->factories[$alias]->createApi($client, $metadata);
24
    }
25
26
    /** {@inheritdoc} */
27 19
    public function has($alias)
28
    {
29 19
        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