HTTPServer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
ccs 0
cts 15
cp 0
wmc 4
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doRequest() 0 4 1
A onRequest() 0 18 3
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\Http\Response;
13
use FastD\Http\SwooleServerRequest;
14
use FastD\Servitization\OnWorkerStart;
15
use FastD\Swoole\Server\HTTP;
16
use Psr\Http\Message\ServerRequestInterface;
17
use swoole_http_request;
18
use swoole_http_response;
19
20
/**
21
 * Class HTTPServer.
22
 */
23
class HTTPServer extends HTTP
24
{
25
    use OnWorkerStart;
26
27
    /**
28
     * @param swoole_http_request  $swooleRequet
29
     * @param swoole_http_response $swooleResponse
30
     *
31
     * @return int
32
     */
33
    public function onRequest(swoole_http_request $swooleRequet, swoole_http_response $swooleResponse)
34
    {
35
        $request = SwooleServerRequest::createServerRequestFromSwoole($swooleRequet);
36
37
        $response = $this->doRequest($request);
38
        foreach ($response->getHeaders() as $key => $header) {
39
            $swooleResponse->header($key, $response->getHeaderLine($key));
40
        }
41
        foreach ($response->getCookieParams() as $key => $cookieParam) {
42
            $swooleResponse->cookie($key, $cookieParam);
43
        }
44
45
        $swooleResponse->status($response->getStatusCode());
46
        $swooleResponse->end((string) $response->getBody());
47
        app()->shutdown($request, $response);
48
49
        return 0;
50
    }
51
52
    /**
53
     * @param ServerRequestInterface $serverRequest
54
     *
55
     * @return Response
56
     */
57
    public function doRequest(ServerRequestInterface $serverRequest)
58
    {
59
        return app()->handleRequest($serverRequest);
0 ignored issues
show
Bug Compatibility introduced by
The expression app()->handleRequest($serverRequest); of type FastD\Http\Response|Symf...HttpFoundation\Response adds the type Symfony\Component\HttpFoundation\Response to the return on line 59 which is incompatible with the return type declared by the abstract method FastD\Swoole\Server\HTTP::doRequest of type FastD\Http\Response.
Loading history...
60
    }
61
}
62