Completed
Push — develop ( c8b131...c09436 )
by Baptiste
04:23
created

RepositoryFactoryConfigurator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 52
c 0
b 0
f 0
ccs 14
cts 15
cp 0.9333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A register() 0 6 1
A configure() 0 18 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Neo4jBundle\Configurator;
5
6
use Innmind\Neo4j\ONM\{
7
    Metadatas,
8
    RepositoryInterface,
9
    RepositoryFactory
10
};
11
use Innmind\Immutable\Map;
12
13
final class RepositoryFactoryConfigurator
14
{
15
    private $metadatas;
16
    private $repositories;
17
18 2
    public function __construct(Metadatas $metadatas)
19
    {
20 2
        $this->metadatas = $metadatas;
21 2
        $this->repositories = new Map('string', RepositoryInterface::class);
22 2
    }
23
24
    /**
25
     * Register a newrepository for the given entity class
26
     *
27
     * @param string $class
28
     * @param RepositoryInterface $repository
29
     *
30
     * @return self
31
     */
32 1
    public function register(string $class, RepositoryInterface $repository): self
33
    {
34 1
        $this->repositories = $this->repositories->put($class, $repository);
2 ignored issues
show
Documentation introduced by
$class is of type string, but the function expects a object<Innmind\Immutable\T>.

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...
Documentation introduced by
$repository is of type object<Innmind\Neo4j\ONM\RepositoryInterface>, but the function expects a object<Innmind\Immutable\S>.

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...
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * Inject registered repositories into the given repository factory
41
     *
42
     * @param RepositoryFactory $factory
43
     *
44
     * @return RepositoryFactory
45
     */
46 2
    public function configure(RepositoryFactory $factory): RepositoryFactory
47
    {
48
        $this
49 2
            ->repositories
50 2
            ->foreach(function(
51
                string $class,
52
                RepositoryInterface $repository
53
            ) use (
54
                $factory
55
            ) {
56 1
                $factory->register(
57 1
                    $this->metadatas->get($class),
58
                    $repository
59
                );
60 2
            });
61
62 2
        return $factory;
63
    }
64
}
65