HTTPServer::doRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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