Completed
Pull Request — 2.11.x (#2448)
by
unknown
12:14
created

RandomConnector   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 22
rs 10
ccs 6
cts 6
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A connectTo() 0 11 2
1
<?php
2
3
namespace Doctrine\DBAL\Connections\Connector;
4
5
use Doctrine\DBAL\Driver\Connection as DriverConnection;
6
use function array_rand;
7
8
/**
9
 * Random connector is connecting to a random slave connection
10
 */
11
class RandomConnector extends AbstractMasterSlaveConnector implements Connector
12
{
13
    public const STRATEGY = 'random';
14
15
    /**
16
     * Connects to a specific connection.
17
     *
18
     * @param string $connectionName
19
     *
20
     * @return DriverConnection
21
     */
22 181
    public function connectTo($connectionName)
23
    {
24 181
        $params = $this->_params;
25
26 181
        $config = $params['master'];
27
28 181
        if ($connectionName !== 'master') {
29 181
            $config = $params['slaves'][array_rand($params['slaves'])];
30
        }
31
32 181
        return $this->connectWithParams($config);
33
    }
34
}
35