Passed
Push — v2 ( 17236d...e5162e )
by Brent
02:04
created

DevelopmentServer::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Application;
4
5
use Stitcher\Command\PartialParse;
6
7
class DevelopmentServer
8
{
9
    private $html;
10
11 2
    public function __construct(
12
        PartialParse $partialParse,
13
        string $rootDirectory,
14
        string $uri = null
15
    ) {
16 2
        $uri = $uri ?? $_SERVER['SCRIPT_NAME'];
17
18 2
        $partialParse->setFilter($uri);
19 2
        $partialParse->execute();
20
21 2
        $filename = ltrim($uri === '/' ? 'index.html' : "{$uri}.html", '/');
22
23 2
        $this->html = @file_get_contents("{$rootDirectory}/{$filename}");
24 2
    }
25
26 2
    public static function make(
27
        PartialParse $partialParse,
28
        string $rootDirectory,
29
        string $uri = null
30
    ): DevelopmentServer
31
    {
32 2
        return new self($partialParse, $rootDirectory, $uri);
33
    }
34
35 2
    public function run(): string
36
    {
37 2
        return $this->html;
38
    }
39
}
40