ProductionServer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 4 1
A handleStaticRoute() 0 14 3
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