Passed
Push — develop ( ec1e42...80559e )
by Brent
03:22
created

DevelopmentServer::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
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
    protected $rootDirectory;
10
    protected $uri = null;
11
    protected $partialParse;
12
13 3
    public function __construct(
14
        string $rootDirectory,
15
        PartialParse $partialParse,
16
        string $uri = null
17
    ) {
18 3
        $this->rootDirectory = $rootDirectory;
19 3
        $this->uri = $uri;
20 3
        $this->partialParse = $partialParse;
21 3
    }
22
23 2
    public static function make(
24
        string $rootDirectory,
25
        PartialParse $partialParse,
26
        string $uri = null
27
    ): DevelopmentServer
28
    {
29 2
        return new self($rootDirectory, $partialParse, $uri);
30
    }
31
32 2
    public function run(): string
33
    {
34 2
        $uri = $this->uri ?? $_SERVER['SCRIPT_NAME'];
35
36 2
        $this->partialParse->setFilter($uri);
37 2
        $this->partialParse->execute();
38
39 2
        $filename = ltrim($uri === '/' ? 'index.html' : "{$uri}.html", '/');
40
41 2
        return @file_get_contents("{$this->rootDirectory}/{$filename}");
42
    }
43
}
44