ManagerServer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 45
ccs 0
cts 23
cp 0
rs 10
wmc 6
lcom 0
cbo 2

2 Methods

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