Passed
Pull Request — master (#14)
by Pavel
03:16
created

StaticApiFactoryFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 10
loc 20
ccs 5
cts 6
cp 0.8333
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 10 10 2
A has() 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\ApiFactoryRegistryInterface;
6
use Bankiru\Api\Doctrine\Exception\MappingException;
7
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
8
use ScayTrase\Api\Rpc\RpcClientInterface;
9
10
final class StaticApiFactoryFactory implements ApiFactoryRegistryInterface
11
{
12
    /** {@inheritdoc} */
13 23 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...
14
    {
15
        /** @var StaticApiFactoryInterface $alias */
16 23
        if (!$this->has($alias)) {
0 ignored issues
show
Documentation introduced by
$alias is of type object<Bankiru\Api\Doctr...ticApiFactoryInterface>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
            throw MappingException::unknownApiFactory($alias);
18
        }
19
20 23
        return $alias::createApi($client, $metadata);
21
22
    }
23
24
    /** {@inheritdoc} */
25 23
    public function has($alias)
26
    {
27 23
        return in_array(StaticApiFactoryInterface::class, class_implements($alias), true);
28
    }
29
}
30