ServerReplier   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 47
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A replying() 0 10 3
A inbound() 0 3 1
A outbound() 0 4 1
A exception() 0 4 1
1
<?php
2
/**
3
 * HTTP server replier
4
 * User: moyo
5
 * Date: 2018/6/6
6
 * Time: 4:01 PM
7
 */
8
9
namespace Carno\HRPC\Handlers;
10
11
use Carno\Chain\Layered;
12
use Carno\Coroutine\Context;
13
use Carno\HTTP\Server\Connection;
14
use Throwable;
15
16
class ServerReplier implements Layered
17
{
18
    /**
19
     * @param mixed $message
20
     * @param Context $ctx
21
     * @return mixed
22
     */
23
    public function inbound($message, Context $ctx)
24
    {
25
        return $message;
26
    }
27
28
    /**
29
     * @param mixed $message
30
     * @param Context $ctx
31
     * @return mixed
32
     */
33
    public function outbound($message, Context $ctx)
34
    {
35
        $this->replying($ctx);
36
        return $message;
37
    }
38
39
    /**
40
     * @param Throwable $e
41
     * @param Context $ctx
42
     * @throws Throwable
43
     */
44
    public function exception(Throwable $e, Context $ctx)
45
    {
46
        $this->replying($ctx);
47
        throw $e;
48
    }
49
50
    /**
51
     * @param Context $ctx
52
     */
53
    private function replying(Context $ctx) : void
54
    {
55
        /**
56
         * @var Connection $ingress
57
         */
58
59
        if (($ingress = $ctx->get(ServerWrapper::CONNECTION))
60
            && ($response = $ctx->get(ServerWrapper::RESPONDING))
61
        ) {
62
            $ingress->reply($response);
63
        }
64
    }
65
}
66