Completed
Push — master ( 7338c3...73871a )
by Adam
03:16
created

Database::createSingleClients()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 10
nc 4
nop 2
1
<?php
2
3
namespace RedisSentinel\Laravel;
4
5
use Illuminate\Support\Arr;
6
use Predis\Client;
7
use Illuminate\Redis\Database as LaravelRedisDatabase;
8
use Predis\Connection\Aggregate\SentinelReplication;
9
use Predis\Connection\ConnectionInterface;
10
11
class Database extends LaravelRedisDatabase
12
{
13
    /**
14
     * Create an array of single connection or sentinel clients
15
     *
16
     * @param  array  $servers
17
     * @param  array  $options
18
     * @return array
19
     */
20
    protected function createSingleClients(array $servers, array $options = [])
21
    {
22
        $clients = [];
23
24
        foreach ($servers as $key => $server) {
25
            $options = array_merge($options, Arr::pull($server, 'options'));
26
27
            $clients[$key] = new Client($server, $options);
28
29
            if (isset($options['update_sentinels']) && boolval($options['update_sentinels']) === true) {
30
                /** @var ConnectionInterface $connection */
31
                $connection = ($clients[$key])->getConnection();
32
33
                if ($connection instanceof SentinelReplication) {
34
                    // is not defined on the interface so make sure we've got the right thing.
35
                    $connection->setUpdateSentinels(true);
36
                }
37
            }
38
        }
39
40
        return $clients;
41
    }
42
}
43