Cluster::meet()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 9.3143
cc 3
eloc 13
nc 1
nop 1
crap 3
1
<?php
2
namespace Phloppy\Client;
3
4
use Phloppy\Exception;
5
use Phloppy\Exception\CommandException;
6
use Phloppy\Stream\StreamException;
7
8
/**
9
 * Disque cluster commands.
10
 *
11
 * @see http://redis.io/commands#cluster
12
 */
13
class Cluster extends AbstractClient {
14
15
16
    /**
17
     * Introduce the provided nodes to the connected Disque instance.
18
     *
19
     * @param string[] $nodeUrls
20
     *
21
     * @return string[]
22
     * @see http://redis.io/commands/cluster-meet
23
     */
24 3
    public function meet(array $nodeUrls)
25
    {
26 3
        $current = $this->stream->getNodeUrl();
27
28 3
        return array_filter($nodeUrls, function($url) use ($current) {
29 3
            if ($url === $current) {
30 1
                return true;
31
            }
32
33 2
            $parts = parse_url($url);
34
35
            try {
36 2
                $response = $this->send(['CLUSTER', 'MEET', $parts['host'], (int) $parts['port']]);
37 2
                $this->log->debug('CLUSTER MEET', ['host' => $url, 'response' => $response]);
38 2
                return 'OK' === $response;
39 1
            } catch (Exception $e) {
40 1
                $this->log->error($e->getMessage(), array('url' => $url, 'exception' => $e));
41 1
                return false;
42
            }
43 3
        });
44
    }
45
}
46