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

DevelopmentServer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

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