Passed
Push — v2 ( 5c6a17...17236d )
by Brent
05:18
created

ProductionServer::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Application;
4
5
class ProductionServer
6
{
7
    protected $html;
8
9 2
    public function __construct(string $rootDirectory, string $uri = null)
10
    {
11 2
        $uri = $uri ?? $_SERVER['SCRIPT_NAME'];
12 2
        $filename = ltrim($uri === '/' ? 'index.html' : "{$uri}.html", '/');
13
14 2
        $this->html = @file_get_contents("{$rootDirectory}/{$filename}");
15 2
    }
16
17 2
    public static function make(string $rootDirectory, string $uri = null): ProductionServer
18
    {
19 2
        return new self($rootDirectory, $uri);
20
    }
21
22 2
    public function run(): string
23
    {
24 2
        return $this->html;
25
    }
26
}
27