Passed
Pull Request — master (#14)
by Pavel
05:12
created

StaticApiFactoryFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
crap 2.0625
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 22 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 22
        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 22
        return $alias::createApi($client, $metadata);
21
22
    }
23
24
    /** {@inheritdoc} */
25 22
    public function has($alias)
26
    {
27 22
        return in_array(StaticApiFactoryInterface::class, class_implements($alias), true);
28
    }
29
}
30