ProductionServer::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
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
namespace Stitcher\Application;
4
5
use GuzzleHttp\Psr7\Response;
6
7
class ProductionServer extends Server
8
{
9
    /** @var string */
10
    protected $rootDirectory;
11
12
    public function __construct(string $rootDirectory)
13
    {
14
        $this->rootDirectory = $rootDirectory;
15
    }
16
17
    public static function make(string $rootDirectory): ProductionServer
18
    {
19
        return new self($rootDirectory);
20
    }
21
22
    protected function handleStaticRoute(): ?Response
23
    {
24
        $path = $this->getCurrentPath();
25
26
        $filename = ltrim($path === '/' ? 'index.html' : "{$path}.html", '/');
27
28
        $body = @file_get_contents("{$this->rootDirectory}/{$filename}");
29
30
        if (!$body) {
31
            return null;
32
        }
33
34
        return new Response(200, [], $body);
35
    }
36
}
37