Passed
Push — develop ( 429d81...1647ec )
by Brent
02:48
created

ProductionServer::handleStaticRoute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 14
ccs 6
cts 7
cp 0.8571
crap 3.0261
rs 9.4285
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
    protected $rootDirectory;
10
11 3
    public function __construct(string $rootDirectory)
12
    {
13 3
        $this->rootDirectory = $rootDirectory;
14 3
    }
15
16 2
    public static function make(string $rootDirectory): ProductionServer
17
    {
18 2
        return new self($rootDirectory);
19
    }
20
21 2
    protected function handleStaticRoute(): ?Response
22
    {
23 2
        $path = $this->getCurrentPath();
24
25 2
        $filename = ltrim($path === '/' ? 'index.html' : "{$path}.html", '/');
26
27 2
        $body = @file_get_contents("{$this->rootDirectory}/{$filename}");
28
29 2
        if (!$body) {
30
            return null;
31
        }
32
33 2
        return new Response(200, [], $body);
34
    }
35
}
36