Passed
Push — master ( 59a5a5...30f57b )
by huang
02:58
created

ManagerServer::onWorkerStart()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ManagerServer::doConnect() 0 4 1
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      http://www.fast-d.cn/
8
 */
9
10
namespace FastD\Servitization\Server;
11
12
use FastD\Application;
13
use FastD\Servitization\OnWorkerStart;
14
use FastD\Swoole\Server\TCP;
15
use swoole_server;
16
17
/**
18
 * Class MonitorStatusServer.
19
 */
20
class ManagerServer extends TCP
21
{
22
    use OnWorkerStart;
23
24
    /**
25
     * @param swoole_server $server
26
     * @param $fd
27
     * @param $from_id
28
     */
29
    public function doConnect(swoole_server $server, $fd, $from_id)
30
    {
31
        $server->send($fd, sprintf('server: %s %s', app()->getName(), Application::VERSION).PHP_EOL);
32
    }
33
34
    /**
35
     * @param swoole_server $server
36
     * @param $fd
37
     * @param $data
38
     * @param $from_id
39
     *
40
     * @return mixed
41
     */
42
    public function doWork(swoole_server $server, $fd, $data, $from_id)
43
    {
44
        switch (trim($data)) {
45
            case 'quit':
46
                $server->send($fd, 'connection closed');
47
                $server->close($fd);
48
                break;
49
            case 'reload':
50
                $this->getSwoole()->reload();
51
                break;
52
            case 'status':
53
            default:
54
                $info = $server->stats();
55
                $status = '';
56
                foreach ($info as $key => $value) {
57
                    $status .= '['.date('Y-m-d H:i:s').']: '.$key.': '.$value.PHP_EOL;
58
                }
59
                $server->send($fd, $status);
60
                break;
61
        }
62
    }
63
}
64