ClientFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neo4j\Neo4jBundle\Factory;
6
7
use GraphAware\Neo4j\Client\Client;
8
use GraphAware\Neo4j\Client\ClientInterface;
9
use GraphAware\Neo4j\Client\Connection\ConnectionManager;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
12
/**
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
final class ClientFactory
16
{
17
    /**
18
     * @var EventDispatcherInterface
19
     */
20
    private $eventDispatcher;
21
22
    /**
23
     * @var ConnectionManager
24
     */
25
    private $connectionManager;
26
27
    /**
28
     * @param ConnectionManager             $connectionManager
29
     * @param EventDispatcherInterface|null $eventDispatcher
30
     */
31 1
    public function __construct(ConnectionManager $connectionManager, EventDispatcherInterface $eventDispatcher = null)
32
    {
33 1
        $this->connectionManager = $connectionManager;
34 1
        $this->eventDispatcher = $eventDispatcher;
35 1
    }
36
37
    /**
38
     * Build an Client form multiple connection.
39
     *
40
     * @param string $names
41
     *
42
     * @return ClientInterface
43
     */
44 1
    public function create(array $names): ClientInterface
45
    {
46
        // Create a new connection manager specific for this client
47 1
        $clientConnectionManager = new ConnectionManager();
48 1
        foreach ($names as $name) {
49 1
            $clientConnectionManager->registerExistingConnection($name, $this->connectionManager->getConnection($name));
50
        }
51
52 1
        $firstName = reset($names);
53 1
        $clientConnectionManager->setMaster($firstName);
54
55 1
        return new Client($clientConnectionManager, $this->eventDispatcher);
56
    }
57
}
58