Passed
Pull Request — develop (#349)
by Schlaefer
15:02 queued 10s
created

Server   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 20
ccs 6
cts 8
cp 0.75
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 5 1
A emit() 0 3 1
1
<?php
2
/**
3
 * @author  PhileCMS
4
 * @link    https://philecms.github.io
5
 * @license http://opensource.org/licenses/MIT
6
 */
7
8
namespace Phile\Http;
9
10
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
11
use Phile\Phile;
12
use Psr\Http\Message\ResponseInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
15
/**
16
 * Runs Phile as standalone application
17
 */
18
class Server
19
{
20
    /** @var Phile app to run */
21
    protected $app;
22
23 8
    public function __construct(Phile $app)
24
    {
25 8
        $this->app = $app;
26
    }
27
28 8
    public function run(ServerRequestInterface $request): ResponseInterface
29
    {
30 8
        $middleware = $this->app->middleware(new MiddlewareQueue());
31 8
        $requestHandler = new RequestHandler($middleware, new ResponseFactory);
32 8
        return $requestHandler->handle($request);
33
    }
34
35
    public function emit(ResponseInterface $response)
36
    {
37
        (new SapiEmitter)->emit($response);
38
    }
39
}
40