Handshake   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
1
<?php
2
/**
3
 * NSQd handshake
4
 * User: moyo
5
 * Date: 15/11/2017
6
 * Time: 3:47 PM
7
 */
8
9
namespace Carno\NSQ\Protocol;
10
11
use Carno\NSQ\Connector\Nsqd;
12
use Carno\Promise\Promised;
13
use Carno\Socket\Contracts\Stream;
14
15
class Handshake
16
{
17
    /**
18
     * magic identify
19
     */
20
    private const MAGIC = '  V2';
21
22
    /**
23
     * Handshake constructor.
24
     * @param Stream $conn
25
     * @param Nsqd $nsqd
26
     * @param Promised $connected
27
     */
28
    public function __construct(Stream $conn, Nsqd $nsqd, Promised $connected)
29
    {
30
        $options = [
31
            'client_id' => sprintf('%d', getmypid()),
32
            'hostname' => gethostname(),
33
            'user_agent' => 'carno-nsq/1.0'
34
        ];
35
36
        $conn->send(self::MAGIC);
37
38
        $nsqd->identify($options)->sync($connected);
39
    }
40
}
41